试图找到平均值
Trying to find the average
本文关键字:平均值 更新时间:2023-12-15
当我试图划分学生1、学生2和学生3时,我需要知道为什么。我认为这可能是一个循环错误,因为它给我的数字是数千,但我不知道这是怎么发生的。
function averageOfThreeScores() {
var student1;
var student2;
var student3;
var end;
do {
student1 = prompt("What are the scorces of students 1?");
student2 = prompt("What are the scorces of students 2?");
student3 = prompt("What are the scorces of students 3?");
end = prompt("Would you like to end, type yes to end.");
var average = (student1 + student2 + student3) / 3;
if (average <= 59) {
document.write(average + " Your score is F <br/>");
} else if (average <= 69) {
document.write(average + " Your score is D <br/>");
} else if (average <= 79) {
document.write(average + " Your score is C <br/>");
} else if (average <= 95) {
document.write(average + "That's a great score <br/>");
} else if (average <= 100) {
document.write(average + "God like </br>");
} else {
document.write(average + " End <br/>");
}
}
while (end != "yes");
}
您希望学生成绩的总和是数字,但事实上它们被连接为字符串。因此,如果用户键入以下值,例如:学生1:13学生2:36学生3:50
平均值为44550,因为总和为(串联字符串):133650
要解决这个问题,只需在获得时将类型转换为数字。
student1 = parseInt(prompt("What are the scorces of students 1?"));
student2 = parseInt(prompt("What are the scorces of students 2?"));
student3 = parseInt(prompt("What are the scorces of students 3?"));
相关文章:
- 平均值:无法将数据更新到数据库
- 使用JS查找数组的平均值
- 平均值.on(事件[,选择器][,数据],处理程序)
- JS:从整个数组中每次得到5个项目,并得到平均值
- 按钮类型是什么;按钮“;JavaScript中的平均值
- 计算数据点阵列与平均值的最大距离,并返回相关数据点
- 当我添加一个新数字时,如何获得一些数字的即时平均值
- 类型错误:无法读取开机自检后未定义的属性“正文”(平均值)
- Javascript提示和警报输入一个数字,它将循环,您将输入数字以获得它的平均值
- Angularjs:访问范围变量数组并计算平均值
- 4个滑块值的平均值
- 标签<<=JavaScript中的平均值
- 什么是;..这个道具;ReactJS中的平均值
- 什么是“;“正”;以及“;否定的“;ECMAScript中的平均值+0和-0
- 什么是“-[1;平均值;if(!-[1,]&&!window.XMLHttpRequest)"
- javascript:NaN,当得到平均值时
- 试图找到平均值
- 从javascript数组计算平均值
- 获取日期直方图的桶平均值,弹性搜索
- 获取angular js中两个下拉值的平均值