Is there something wrong with this? Final Grade module JavaScript

So, I’m doing this exercise, I write the code, I’m told it’s wrong and yet when I test it out it seems to work just fine and I used less lines of code. Did I do something wrong? Because I’m not seeing it.

The code I wrote is on top and the solution is on the bottom.

 const finalGrade = (midterm, final, homework) =>{
  const average = ((midterm+final+homework)/3)
  if (average<0 || average>100){
    return 'Invalid grade'
  } if (average <= 59) {
    return 'F';
  } if (average <= 69) {
    return 'D';
  } if (average <= 79) {
    return 'C';
  } if (average <= 89) {
    return 'B';
  } if (average <= 100) {
    return 'A';
  } 
}




const finalGrade = (midterm, final, homework) => {
    if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100)) {
        return 'You have entered an invalid grade.'
    }
    let average = (midterm + final + homework) / 3
    if (average < 60) {
        return 'F'
    }
    else if (average < 70) {
        return 'D'
    }
    else if (average < 80) {
        return 'C'
    }
    else if (average < 90) {
        return 'B'
    } else {
        return 'A'
    }
}

Hello, @wyrm616. Your code only tests the average score for validity. You need to test each parameter for validity. Your code will still return a letter grade even if one of the parameters is less than zero or greater than one-hundred.

3 Likes

Ohhhh, I see what your saying if. So, if I were to put finalGrade(101, 76, 39) it should return an invalid grade. But what if I got extra credit on my final??? :rofl:

Thanks for the help!

2 Likes