简体   繁体   中英

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

I believe what you have done is almost correct. They want you to pass the score out of 100 and tell the grade. So after some major tweaks in your code it looks like this.

 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));

Change the score in the grade calling function at the bottom [grade(85);] and check for change in the grade.

Hope this solves your question.

You did not defined the function argument. provide an argument to the function . you refereed the function name in the function body that is the problem with your code

 function grade(mark){
      
        if(mark = 100 && mark >=90 )
    
        {
          return 'you got an A';
          
        }
    
        if(mark >= 80 && mark <= 89 )
        
        {
          return 'you got a B';
        }
    
        if(mark >= 70 && mark <= 79 )
    
        {
          return 'you got a C';
        }
    
        if(mark >= 60 && mark <= 69 )
    
        {
          return 'You got a D';
        }
    
        if(mark <= 60 )
    
        {
          return 'you got a F';
        }
        
      }

You don't need the condition for max

 function grade(score){ if(score >=90 ) { return 'you got an A'; } else if(score >= 80) { return 'you got a B'; } else if(score >= 70) { return 'you got a C'; } else if(score >= 60) { return 'You got a D'; } else { return 'you got a F'; } } console.log(grade(78));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM