gpt4 book ai didi

Javascript - 无法获得要警报的数组的平均值

转载 作者:行者123 更新时间:2023-11-28 19:54:31 28 4
gpt4 key购买 nike

我希望这对于专家来说会是一件非常简单的事情。因此,我的代码可以接收一些学生姓名及其各自的分数。到目前为止,一切都很好。但是,当它到达最后时,它应该将标记放在一起并找到平均值,然后向用户提醒平均值。但是,就目前情况而言,我没有收到任何警报。代码如下:

var sQuantity = parseInt(prompt("Let's begin compiling our student database. How many students would you like to enter?", "Number of Students")); 

var sList = new Array();
var sMarks = new Array();

for (var count = 0; count < sQuantity; count++) {
sList.push(prompt("Please enter the Student's Name", "Students Name"));
}

var i = 0;

for (var count = 0; count < sQuantity; count++) {
sMarks.push(parseInt(prompt("Please enter " + sList[i] + "'s average grade for this course.", "Enter Average Grade")));
var i=(i+1);
}

var sum = 0;
var cAverage = 0;

for (i = 0; i < sMarks.length; i++) {
sum = (sum + sMarks[i]);
}

cAverage = (Sum/sMarks.length);

alert(cAverage);

为什么代码没有在警报中显示平均值?

最佳答案

变量区分大小写,替换

cAverage = (Sum/sMarks.length); 

cAverage = (sum/sMarks.length); 

它有效

FIDDLE

关于Javascript - 无法获得要警报的数组的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22823066/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com