Codewars:蚱hopper

编程入门 行业动态 更新时间:2024-10-06 18:34:48
本文介绍了Codewars:蚱hopper-年级挑战书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是解决方案盯着我盯着我,但我似乎找不到它的那些时候之一!因此,请耐心等待我. 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

本文发布于:2023-11-30 18:39:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Codewars   hopper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!