I created a multidimensional array:
var students = [ [['David'], [80]], [['Vinoth'], [77]], [['Goren'],[55]] ];
Then I created an if statement that will test if the student's grade is F to A.
for (var i = 0; i < students.length; i++) {
for (var j = 1; j < students.length; j++) {
document.write(students[i][j] + "<br/>");
if (students[i][j] < 60) {
document.write(students[i][j] + " is Grade : F");
} else if (students[i][j] < 70) {
document.write(students[i][j] + " is Grade : D");
} else if (students[i][j] < 80) {
document.write(students[i][j] + " is Grade : C");
} else if (students[i][j] < 90) {
document.write(students[i][j] + " is Grade : B");
} else if (students[i][j] < 100) {
document.write(students[i][j] + " is Grade : A");
}
}
}
In my pursuit to output the name of the student and the grade, I even ended up creating three for loops, which did not work.
I was wondering how can I achieve this output:
David's grade is 80 and is C Grade.
Vinoth's grade is 77 and is C Grade.
Goren's grade is 55 and is F Grade.
What am I missing?
students.lengthas the limit for bothforloops?