OK, so I am attempting to write some code that will take x number of classrooms and x number of students per classroom and then pair two students together randomly from separate classrooms.
Sounds Simple, right! I have already been able to create x number of input elements dynamically on the page and all works up until I try to create the array for the x number of elements.
Is there a different approach I should Try?
I got my code working up til this point:
for (i = 0; i < classSize; i++) {
var arrField = container2.appendChild(document.createElement('fieldset'));
var arrDiv = arrField.appendChild(document.createElement('div'));
arrDiv.id = "div" + (i + 1);
var studentArr = "studentArr" + (i + 1);
alert(studentArr); //returns "studentArr1" "studentArr2", etc.
for (n = 0; n < arrSize; n++) {
studentArr = new student();
studentArr[(n + 1)] = new student(document.getElementById("name" + (n + 1)).value, document.getElementById("email" + (n + 1)).value, document.getElementById("phone" + (n + 1)).value);
alert(studentArr[(n + 1)].name);
alert(studentArr[(n + 1)].email);
alert(studentArr[(n + 1)].phone);
}
}
FYI- I am very new to JavaScript and programming in general!- Sorry