gpt4 book ai didi

javascript - 将数字成绩转换为字母成绩 - 显示成绩的问题

转载 作者:行者123 更新时间:2023-12-01 01:43:55 25 4
gpt4 key购买 nike

我在让代码运行下面的 if 语句时遇到问题。我正在上网课,我唯一的资源就是课本。感谢帮助。我能够让它返回除提示、错误消息之外的任何内容并退出程序。它正在正确运行连续循环。

var numberGrade;
var grade = [];
do {
numberGrade = prompt("Enter number grade from 0 through 100\nOr enter -1 to end entries\n");
numberGrade = parseInt(numberGrade);
if (numberGrade >= 0 && numberGrade <= 100 ) {
grade[grade.length] = numberGrade;
} else if (numberGrade != -1) {
alert("Entry not valid!\n Entry must be a valid number from 0 through 100 \n Or enter -1 to end entries");
}
}
while (numberGrade != -1);

for (var num = 0; num <= grade; num++) {
if (grade >= 0 && grade <= 59) {
alert ("Number grade =" + grade + "\nLetter Grade = F");
}
if (grade >= 60 && grade <= 62) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = D-");
}
if (grade >= 63 && grade <= 66) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = D");
}
if (numberGrade >= 67 && numberGrade <= 69) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = D+");
}
if (numberGrade >= 70 && numberGrade <= 76){
alert ("Number grade =" + numberGrade + "\nLetter Grade = C");
}
if (numberGrade >= 77 && numberGrade <= 79) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = C+");
}
if (numberGrade >= 80 && numberGrade <= 82) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = B-");
}
if (numberGrade >= 83 && numberGrade <= 86) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = B");
}
else if (numberGrade >= 87 && numberGrade <= 89) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = B+");
}
if (numberGrade >= 90 && numberGrade <= 92) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = A-");
}
if (numberGrade >= 93 && numberGrade <= 100) {
alert ("Number grade =" + numberGrade + "\nLetter Grade = A");
}
}

最佳答案

在循环初始化中,语句 num <= grade没有意义,因为 grade是一个数组而不是一个数字。将循环更改为 for (var num = 0; num < grade.length; num++) 。那么你的if语句应针对 grade 的元素进行测试数组:

if (grade[num] >= 0 && grade[num] <= 59) {
alert ("Number grade =" + grade[num] + "\nLetter Grade = F");
}

关于javascript - 将数字成绩转换为字母成绩 - 显示成绩的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52124041/

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