Is there a way to assign multiple values of objects using a loop in Java?

The question requires us to create two objects of the Student class and have 5 variables. The variables will be assigned a value each through user input.
I was wondering if there is any way to use a loop or anything else to take the user inputs from there instead of writing each variable individually using the dot operator.
Here is the code:

    public class Main{

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Student student1 = new Student();
        Student student2 = new Student();

        //Input for student 1
        student1.name = input.nextLine();
        student1.gender = input.next().charAt(0);
        student1.cgpa = input.nextDouble();
        student1.roll[0] = input.nextInt();
        student1.age = input.nextInt();

        //Input for student 2
        student2.name = input.nextLine();
        student2.gender = input.next().charAt(0);
        student2.cgpa = input.nextDouble();
        student2.roll[0] = input.nextInt();
        student2.age = input.nextInt();

    }
}

class Student{
    String name;
    char gender;
    double cgpa;
    int[] roll;
    int age;
}

Why cant i change the value of something in an array

When i console.log the winConditions array it shows all zeroes when its supposed to have some 1’s in it aswell.

I’m changing the value of a, b and c at the click event listener but idk why they are not changing

Someone please help me

let a = 0,
    b = 0,
    c = 0,
    d = 0,
    e = 0,
    f = 0,
    g = 0,
    h = 0,
    i = 0;

const test = document.querySelector(".gameboard");
test.addEventListener("click", () => {
    a = 1;
    b = 1;
    c = 1;
    gameBoard.applyWinConditions;
    console.log(gameBoard.winConditions)
    gameBoard.gameFlow.checkScore();
});



const gameBoard = (() => {
    let gameBoard = {};
    let applyWinConditions = () => {  
        gameBoard.winConditions = [[a, b, c], [a, d, g], [a, e, i], [b ,e, h], [c, e, g], [c, f, i], [d, e, f], [g, h, i]]; 
        return gameBoard.winConditions;
    }
    const gameFlow = (function() {
        
        const _isEveryElementOne = (arr) => {
            return arr.every(el => el === 1) 
        }
        const _announceWinner = () => console.log("game ends");
    
        return {
            checkScore: () => {
                console.log(gameBoard.winConditions);
                if (gameBoard.winConditions.some(cond => _isEveryElementOne(cond))) return _announceWinner()
                console.log("game continues")
            },
            
        };
    })();
    
    return {
        gameFlow,
        applyWinConditions: applyWinConditions(),
        winConditions: gameBoard.winConditions,  
    }
})();

gameBoard.applyWinConditions;
console.log(gameBoard.applyWinConditions)

Why dynamic values are not being submitted from form with NextJS?

I’m working on React based on NextJS code.

If I manually enter values in form fields and submit the form, I get all the values in the component function.

But if I dynamically display values in a form field like value={query.campaignid}, the component does not collect any value.

import { Button, Input } from "@chakra-ui/react";
import { Field, Form, Formik } from "formik";

import { useRouter } from "next/router";

export default function FormikExample() {
  const { query } = useRouter();

  return (
    <>
      <Formik
        initialValues={
          {
            // campaignid: " ",
          }
        }
        onSubmit={(values) => {
          setTimeout(() => {
            console.log(values);
          });
        }}
      >
        {(props) => (
          <Form>
            <Field name="campaignid">
              <Input value={query.campaignid} />
            </Field>

            <Button id="submited" isLoading={props.isSubmitting} type="submit">
              Submit
            </Button>
          </Form>
        )}
      </Formik>
    </>
  );
}

why is it not repeatedly console.log in setTimeout()

I am totally new to the concept of promises and asynchronous programming and have a hard time wrapping my mind this setTimeout() function why this would work: it would console.log() every
time i increments.

let i = 1;
setTimeout(function run() {
   console.log(i);
   i++;
   setTimeout(run, 1000);
}, 1000);

while console.log() a different value would just console.log() once.

setTimeout(function run() {
   console.log(".");
   i++;
   setTimeout(run, 1000);
}, 1000);

Can someone help explain the logic behind this? Thanks.

Is there any tools or code that ready for use it to adding maps in my react website?

I want adding map in my website and I prefer this map to have interactive functionality such as when I zoom it to specific location the names of defined shops -by me- or the name on street and Neighborhood to be appear.
I have example of that from RentBerry website (https://rentberry.com/apartments/s/new-york-ny) as in photo 1 :
is there any ready code or tool that my help me?

Save data from html input to .csv file

I have created a form using HTML, CSS and js only and I wanted to data from that form to a CSV file locally don’t want to use php and such. Let’s say my from have first name, date of birth, some radio buttons and some drop-down menus and on submit I wanted to save all the data in a .csv file.

Thanks in advance and any advice will be helpful

redux reducer… + 1 I have created a new array and added one. now how do I put it back together and return the new state

so found the index of what I want to change, I created a new array newFavorites and increased a value on one of its keys (sets +1). But I am not sure how to return the new state with the updated key value.

  case ADD_SETS: 
                const favToIncreaseSet = state.favoritedExercises.findIndex(fav => fav.id === action.payload.id);
                const newFavorites = [...state.favoritedExercises];
                let repIncreasedFav = newFavorites[favToIncreaseSet].sets + 1;
               
                
                return { ...state, newFavorites}

Update array of objects depend on values from another array [duplicate]

The array of Objects and different arrays with values. Need to know how to update the data object depended on that value. Value in array matches id in data. Thx much for help

{
   "data":[
      {
         "id":1,
         "name":"name1",
         "active":false
      },
      {
         "id":2,
         "name":"name2",
         "active":false
      },
      {
         "id":3,
         "name":"name3",
         "active":false
      }
   ]
}

Array of values

values = [1,3]

How should look

{
   "data":[
      {
         "id":1,
         "name":"name1",
         "active":true
      },
      {
         "id":2,
         "name":"name2",
         "active":false
      },
      {
         "id":3,
         "name":"name3",
         "active":true
      }
   ]
}

Download audio file from html with javascript function

I’m trying to download an mp3 file on the click of a button, it downloads, but the file it downloads is not correct, it’s a WAY smaller file than the original one (25 bytes), while the original one is 10MB.

It’s my first time working with downloading stuff so I’m pretty clueless.

Here’s some code:

JS function:

 function download(i) {
    var audio = document.getElementById("audio"+i);

    const blob = new Blob(, {type:"octet-steam"});

    const href = URL.createObjectURL(blob);

    const a = Object.assign(document.createElement("a"), {
        href, 
        style: "display:none",
        download: "myAudio.mp3",
    });
    document.body.appendChild(a);

    a.click();
    URL.revokeObjectURL(href);
    a.remove();
}

Audios are identified by their ID and their file name comes from the data I have in a database.
HTML/PHP

for($i=0; $i<$count; $i++){
  $res = mysqli_fetch_array($result);
  echo('<tbody id="tbody">
  <tr>
  <audio id="audio'.$i.'" src="mp3/'.$res["song_artist"].'-'.$res["song_title"].'.mp3"> 
  <td><button onclick="download('.$i.')">&#8628</button></td>
  </tr>
</tbody>');
}    

Check if half of a period has passed

I have a system where the user can choose a period where after this period he earns for example + 2% of the sum he has chosen. If he tries to make an action with this sum before the half of the period it loses a percentage of its value. So what I want to know is how to calculate half of a date.

In my example:

I have for example in a mysql table the date when he put the sum and the date when the defined period will be finished.
So if it is 24-2-2022 and he chooses in 6 months, there will be two pieces of information in the database 24-2-2022 and 24-8-2022.
What I’ve done so far is split() the date to separate day, month and year. But here I am stuck because I do not know how to compare all this to see if the period is halfway or not.

open children and close other children in multi-level navigation

I am working on a navigation and now managed to open up deeper levels of a certain parent one by one on click but I have a hard time trying to figure out how to close all others when going into a another direction.

Let’s say you have A1, A2A, A3A and A4A open and you click on B1, then I want A1A, A2A and A3A to close. But it also needs to work midway: let’s say you have A1, A2A, A3A and A4A open but you click on A2B then A3A and A4A need to close.

$('li.has-children').click(function(){

        $(this).children('.wrap').addClass('active');
        
    });
.wrap {
  display:none;
}

.active {
  display:inline-block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li class="has-children">
    <a class="">link A1</a>
    <div class="wrap wrap-0">
    <ul>
      <li class="has-children">
        <a class="">link A2A</a>
        <div class="wrap wrap-1">
        <ul>
          <li class="has-children">
            <a class="">link A3A</a>
            <div class="wrap wrap-2">
              <ul>
                <li class="has-children">
                  <a class="">link A4A</a>
                </li>
              </ul>
            </div>
          </li>
        </ul>
        </div>
      </li>
      <li class="has-children">
        <a class="">link A2B</a>
        <div class="wrap wrap-1">
        <ul>
          <li class="has-children">
            <a class="">link A2B</a>
            <div class="wrap wrap-2">
              <ul>
                <li class="has-children">
                  <a class="">link A3B</a>
                </li>
              </ul>
            </div>
          </li>
        </ul>
        </div>
      </li>
    </ul>
    </div>
  </li>
  <li class="has-children">
    <a class="">link B1</a>
    <div class="wrap wrap-0">
    <ul>
      <li class="has-children">
        <a class="">link B2A</a>
        <div class="wrap wrap-1">
        <ul>
          <li class="has-children">
            <a class="">link B3A</a>
            <div class="wrap wrap-2">
              <ul>
                <li class="has-children">
                  <a class="">link B4A</a>
                </li>
              </ul>
            </div>
          </li>
        </ul>
        </div>
      </li>
      <li class="has-children">
        <a class="">link B2B</a>
        <div class="wrap wrap-1">
        <ul>
          <li class="has-children">
            <a class="">link B3B</a>
            <div class="wrap wrap-2">
              <ul>
                <li class="has-children">
                  <a class="">link B4B</a>
                </li>
              </ul>
            </div>
          </li>
        </ul>
        </div>
      </li>
    </ul>
    </div>
  </li>
</ul>

TypeError: discord_js_1.Intents is not a constructor after making a timeout command?

so I was coding the timeout command and when I wanted to try it out I got the following error

TypeError: discord_js_1.Intents is not a constructor

Before even having the timeout command and when I made the timeout command I suddenly got this error.

Here is my timeout code:

const { CommandInteraction } = require("discord.js");

module.exports = {
    name: "timeout",
    description: "Timeout a member.",
    options: [
        {
            name: "user",
            description: "Member to perform the timeout on",
            type: "USER",
            required: true
        },
        {
            name: "length",
            description: "Length of the timeout.",
            type: "STRING",
            required: true
        },
        {
            name: "reason",
            description: "Reason for this timeout.",
            type: "STRING",
            required: true
        }
    ],
    /**
     * 
     * @param {CommandInteraction} interaction 
     */
    async execute(interaction){
        const user = interaction.options.getUser("user")
        const length = interaction.options.getString("length")
        const reason = interaction.options.getString("reason")
        const member = interaction.guild.members.cache.get(user.id)

        const timeInMs = ms(length);
        if(!timeinMs) return interaction.followUp("Please specify a valid time!");

        member.timeout(timeInMs, reason)
        interaction.followUp(`${user} has been timeouted for ${length}! (${reason})`)

    }
};

I don’t know why I am suddenly getting this error, could someone help me about this?

Application being able to self update with github

I’m creating a bot app with Node.JS and I’d like to make it able to update its dependecies automatically without needing to turn it off and do it manually, I want that the bot itself could programatically use the “npm update”.

But more important than that, I want that it could self update its own code if I make a “git push” on its repo. However, I don’t want to do it with every push, just chosen ones. After researching, I found GitHub Actions, but I’m still a little lost about it.

Thanks in advance.

How to get the result from a forEach loop?

I have the code below, which is working (i.e. I can print the index to the console). However, I’d like to use that index outside of the forEach loop. I have tried random things like returning the tabIndex, wrapping it all in a function etc. but I don’t get it right or understand the steps needed.

The plan is to use the index to fetch data from a JSON file.

Any suggestions on how to make the result from tabIndex globally available?

/* DESTINATION TABS */
    const destinationTabs = document.querySelectorAll(".destination-info--tab");
    
    /* Get index of the clicked tab */
    destinationTabs.forEach((destinationTab) => {
      destinationTab.addEventListener("click", (e) => {
        const tabIndex = Array.from(destinationTabs).indexOf(e.target);
        console.log(tabIndex);
      });
    });