I have two arrays displayed below and I am trying to calculate the sum, average, and create a summary showing the course along with the grade.
grades = new Array();
courses = new Array("Mathematics", "Statistics", "Algorithm");
However, my summary is not working as expected, even after adding an extra loop...
grades = new Array();
courses = new Array("Mathematics", "Statistics", "Algorithm");
function main(){
var sum = 0;
var average = 0;
for(var i = 0; i<courses.length; i++){
var note = parseInt(prompt("Enter the grade for " + courses[i] + ": "));
grades.push(note);
sum += note;
}
average = sum / 3;
document.write("Sum of grades: " + sum + "<br>");
document.write("Average grade: " + average + "<br>");
document.write("Summary : " + "<br>");
for(var i = 0; i<courses.length; i++){
document.write("Course: " + courses[i] + " - Grade: " + note[i] + "<br>");
}
}
Any suggestions on how to fix this issue?
<body onload="main()">
<center><h2>Exercise 4.8</h2></center>
</body>