Struggling to implement the loop function on an array, I am seeking assistance. My goal is to assign people's requests to groups based on vacancies in those groups automatically.
Therefore, I envision a table like this:
Group 1 | Number of People
Group 2 | Number of People
Group 3 | Number of People
and so forth...
To achieve this, I understand that I need an "if" condition to compare reservation requests with group vacancies and then make the assignment if the vacancy exceeds the request.
I can add the reservation variable to an array using the array.push function but I'm facing challenges in looping through and assigning values to a two-column array...
<label for="groups">Reservation request (1-10):</label>
<div id="reservation">
<input type="number" name="form" id="number" min="1" max='10'>
<br><br>
<button onclick="groups()">Submit</button>
</div>
var myArray = ["Group 1", "Group 2", "Group 3"];
function groups() {
form = number.value;
if (form >=1){
for (var i; i<myArray.length; i++) {
if (myArray[i] > form){
myArray[i] = form;
console.log(myArray);
}
else {alert("no");}
}
}
Can anyone offer guidance?
Thank you, Marion