javascript - Javascript Student - Question - Grade Calculator
问题描述
[GIT BASH IMAGE][1] https://i.stack.imgur.com/Akyjx.png
Below I've tried adding in some number 1-100 inside the function itself for example; Function grade(85)
I've also tried assigning a variable let = 85.
I guess I'm not understanding what they mean by "Receive a score out of 100". I need help getting this number plugged into this script here. I have included the gitbash error that I'm receiving which makes me think that it's something that needs to be included with the function. Thank you
//Grade Calculator
/*
Using the grade function below do the following:
1. Receive a score out of 100
2. Return the corresponding letter grade following this grade scale:
90-100 = A
80-89 = B
70-79 = C
60-69 = D
below 60 = F
*/
function grade(){
if(grade = 100 && grade >=90 )
{
return 'you got an A';
}
if(grade >= 80 && grade <= 89 )
{
return 'you got a B';
}
if(grade >= 70 && grade <= 79 )
{
return 'you got a C';
}
if(grade >= 60 && grade <= 69 )
{
return 'You got a D';
}
if(grade <= 60 )
{
return 'you got a F';
}
}
[1]: https://i.stack.imgur.com/Akyjx.png
解决方案
我相信你所做的几乎是正确的。他们希望你通过满分 100 分并说出成绩。因此,在对代码进行一些重大调整后,它看起来像这样。
function grade(score){
if(score == 100 || score >=90 )
{
return 'you got an A';
}
else if(score >= 80 && score <= 89 )
{
return 'you got a B';
}
else if(grade >= 70 && grade <= 79 )
{
return 'you got a C';
}
else if(score >= 60 && score <= 69 )
{
return 'You got a D';
}
else
{
return 'you got a F';
}
}
console.log(grade(85));
在底部 [grade(85);] 的成绩调用函数中更改分数并检查成绩的变化。
希望这能解决你的问题。
推荐阅读
- python - 提取 URL 的“Think Python”练习
- java - Java 类中调用的语句是什么?
- python - Python:在函数中给出 NameError 的 Eval
- ruby-on-rails - Rails 使用record_type 和recored_id 连接表,如activestorage
- html - 为什么 type="number" 属性会破坏 Firefox 中的解析?
- sql - 3个进程的Sql Server死锁问题
- azure-cognitive-search - 如何在 Azure 搜索中添加自定义字段
- excel - 通过 VBA 在书签后在 Word 中插入 Excel 单元格文本
- javascript - 如果用户单击该行上的折叠按钮,如何禁用整行的 onclick?
- usb - USB 外围设备的 bIntervals 是如何执行的?