我的代码随机停止,我不知道为什么。有什么建议吗?



我不确定为什么我的代码不能工作?在要求用户输入考试成绩后,它只会停止并显示第一个学生的用户输入,而不询问其他学生的任何信息。

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
var names = new Array(); 
var tests = new Array();
var high =0; 
var low = 0;  
var numOfStudents = prompt("How many students are in the class? "); 
numOfStudents = parseInt(numOfStudents);
var i = 0; 
for (i=0; i<=numOfStudents - 1; i++){
names[i] = prompt("Enter the students name: "); 
document.write("Name of Student: " + names[i]);
var numOfTest = prompt("How many test were administered for this student? ");
numOfTest = parseInt(numOfTest);
for (i=0; i<=numOfTest -1; i++){
tests[i] = prompt("Enter the test grade: "); 
document.write(" Grade: "+ tests[i] + "<br />"); 
}
}

</script>
<body>
</body>
</html>

为第二个循环选择另一个变量名

for (var j=0; j<=numOfTest -1; j++){
tests[j] = prompt("Enter the test grade: "); 
document.write(" Grade: "+ tests[j] + "<br />"); 
}

最新更新