gpt4 book ai didi

JavaScript 多次打印

转载 作者:行者123 更新时间:2023-11-30 17:32:17 25 4
gpt4 key购买 nike

你好,我想让用户输入一些分数,最后给出最高分和最低分,但出于某种原因,它打印了两次,第二次打印了无穷大和想法?

    var gradeAwarded;
var gradeAwarded;
var repeate = true;
var max;
var A;
var B;
var C;
var F;

var repeat, studentArr = [], markArr = [];
while (repeat !== 'n' && repeat !== 'N'){
studentArr.push(prompt("Enter Student Name: "));
markArr.push(parseInt (prompt("Enter Student mark: ")));
repeat = prompt ("Do you want to enter another student: y/n");
}

Array.prototype.max = function() {
return Math.max.apply(Math, markArr);
};

Array.prototype.min = function() {
return Math.min.apply(Math, markArr);
};
var min = markArr.min();
var max = markArr.max();


if (markArr <0 || markArr >100){
alert("Grate out of bounds");
}else if (markArr >= 83){
gradeAwarded = "A";
A = +1;
}else if (markArr >= 70){
gradeAwarded = "B";
B = +1;
}else if (markArr >= 50){
gradeAwarded = "C";
C = +1;
}else if (markArr >= 0){
gradeAwarded = "F";
F = +1;
}

document.write("The Highest mark was : "+max);
document.write("The Lowest mark was : "+min);

最佳答案

必须是||而不是 &&

while (repeat !== 'n' || repeat !== 'N'){
studentArr.push(prompt("Enter Student Name: "));
markArr.push(parseInt (prompt("Enter Student mark: ")));
repeat = prompt ("Do you want to enter another student: y/n");
}

并且您还应该清除或将null设置为重复过程中的变量

关于JavaScript 多次打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22753311/

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