gpt4 book ai didi

javascript - 密码战 : Grasshopper - Grade book challenge

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

这是解决方案就在我面前,但我似乎找不到的时候之一!所以请耐心等待我。 kata instruction是以下内容:

Complete the function so that it finds the mean of the three scores passed to it and returns the letter value associated with that grade.

Numerical Score       Letter Grade

90 <= score <= 100 'A'
80 <= score < 90 'B'
70 <= score < 80 'C'
60 <= score < 70 'D'
0 <= score < 60 'F'

Tested values are all between 0 and 100. There is no need to check for negative values or values greater than 100.

这是我的解决方案:

function getGrade (s1, s2, s3) {
var score = (s1 + s2 + s3) / 3;
if (90 <= score && score >= 100) {
return 'A';
} else if (80 <= score && score > 90) {
return 'B';
} else if (70 <= score && score > 80) {
return 'C';
} else if (60 <= score && score > 70) {
return 'D';
} else if (0 <= score && score > 60) {
return 'F';
}
}

getGrade(5,40,93);
getGrade(30,85,96);
getGrade(92,70,40);

我这辈子都弄不明白我做错了什么。

最佳答案

你在 if 语句中的条件都是错误的。这些是合适的条件

function getGrade (s1, s2, s3) {
var score = (s1 + s2 + s3) / 3;
if (score >= 90 && score <= 100) {
return 'A';
} else if (score >= 80 && score < 90) {
return 'B';
} else if (score >= 70&& score < 80) {
return 'C';
} else if (score >= 60 && score < 70) {
return 'D';
} else {
return 'F';
}
}

关于javascript - 密码战 : Grasshopper - Grade book challenge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930614/

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