我今天在大学做了一个练习,它是一个JavaScript程序来计算测试中学生的平均分数.
这是我的代码:
<!DOCtype html>
<html>
<head>
<title>While loop</title>
</head>
<body>
<script>
//The total score of all pupils
var total = 0;
//The number of scores
var count = 1;
while (count <= 10) {
grade = prompt("Insert the grade:");
total = total + grade;
count++;
}
var average = +total / 10;
document.write("The average is " + average);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我输入的值是10-100,上升10到10.所以我把10个值"10,20,30,40,50,60,70,80,90,100"放进去,而不是得到平均值,我得到了所有这些值并排.
我究竟做错了什么?
javascript ×1