首页 > 解决方案 > 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

标签: javascript

解决方案


我相信你所做的几乎是正确的。他们希望你通过满分 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);] 的成绩调用函数中更改分数并检查成绩的变化。

希望这能解决你的问题。


推荐阅读