这是解决方案盯着我盯着我,但我似乎找不到它的那些时候之一!因此,请耐心等待我. kata指令如下:
This is one of those times where the solution is staring me right in the face but I can't seem to find it! So please be patient with me. The kata instruction is the following:
完成该函数,以便找到传递给它的三个分数的平均值,并返回与该年级相关的字母值.
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'
测试值都在0到100之间.无需检查负值或大于100的值.
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);无法终生认清自己在做错什么.
Can't for the life of me figure out what I am doing wrong.
推荐答案您的条件不正确,如果不需要,则不需要多次检查.将代码更改为此:
your conditions are wrong and you don't need multiple check in same if .Change your code to this:
function getGrade (s1, s2, s3) { var score = (s1 + s2 + s3) / 3; if (score >= 90 && score <= 100) { return 'A'; } else if (score >= 80 ) { return 'B'; } else if (score >= 70 ) { return 'C'; } else if (score >= 60) { return 'D'; } else{ return 'F'; } } console.log(getGrade(5,40,93)); console.log(getGrade(30,85,96)); console.log(getGrade(92,70,40));
更多推荐
Codewars:蚱hopper
发布评论