我在尝试使用JavaScript并创建了一个多维数组:
var students = [ [['David'], [80]], [['Vinoth'], [77]], [['Goren'],[55]] ];
然后,我创建了一个if语句,用于测试学生的成绩是否为F到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");
}
}
}
在我追求输出学生姓名和成绩的过程中,我甚至创建了三个for循环,但都没有成功。我在想如何实现以下输出:
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.
你有没有想过为什么代码出现问题?
students.length
作为限制? - Barmar