I've got some kind of mental block while developing the code for this particular program.
Instructions to create a flexible marks storing database: Ask the user how many students there are. Using a for loop and prompt statements, ask the user for the student names. Store them in an array. Using a for loop and prompt statements, ask the user for the marks (include the name of the class) for each student. Store them in an array. Calculate the average mark for the class, and print it out on the screen.
It looks like got somewhere with the code but I've having difficulty combing the second for-loop to calculate the average of the marks of the number of students. I believe the error results because I didn't declare all the necessary variables and also my array structure is wrong; like the way I declared and stored the elements.I think a few steps are missing from the code.
var howManyStudents = 0;
var studentGradesAverage = 0;
var marksTotal = 0;
howManyStudents = parseInt(prompt("How any students are in this class?", "enter a number"));
document.writeln("<p> There are " + howManyStudents + " students in this class </p>");
var studentNames = Array(howManyStudents);
var classGrades = Array(howManyStudents);
var allStudents = Array(studentNames, classGrades);
for (var i = 0; i < howManyStudents; i++) {
allStudents[0][i] = prompt("Please enter the name of the student.", "Student Name").toString();
// reference a student Math grade
allStudents[1][i] = parseFloat(prompt("Enter the student's Grade. The Grade are between 0 to 100. "));
marksTotal += allStudents[1][i];
}
studentGradesAverage = marksTotal/howManyStudents;
document.writeln("<p> Average per class is: " + studentGradesAverage + "</p>");