finalGrade

I am working on the finalGrade project and could use some feedback. I just started this course 2 weeks ago and love it but totally don’t get it!

const finalGrade = (term1, term2, term3) => { if ((term1 < 0 || term1 > 100) || (term2 < 0 || term2 > 100) || (term3 < 0 || term3 > 100)){ return 'You have entered an invalid grade.' } let average (term1 + term2 + term3) / 3 } } if (average <100){ return 'A' } else if (average < 90){ return 'B' } else if (average <80) { return 'C' } else if (average <70) { return 'D' } else { return 'F' } console.log(finalGrade(99, 92, 95

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-practice-javascript-syntax-variables-data-types-conditionals-functions/lessons/javascript-fundamentals-code-challenge/exercises/final-grade

Looks like you are trying to assign the variable average to the result of an equation. You need to use the assignment operator to make an assignment.

Hint
let someVariable = someValue;
//               ^
//      assignment operator

Once that’s fixed you have a few more issues. Read the error messages carefully, and see if they don’t guide you to what to fix. Also, once you have it working without errors, try calling your function with all zeros for grades: finalGrade(0, 0, 0)

Thank you so much! That was helpful.

I don’t always get the error messages. Like below, it gives this message but my code is exactly the same as in the solution.
(I am very new to this so if I am too needy, or don’t follow guidelines, just let me know!
Your help is very much appreciated!

if (average < 100){
^^
SyntaxError: Unexpected token if
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

May seem like it, but that can’t be true unless either the solution code throws the same error if you copy, and run it, or your computer requires fine tuning with a sledge hammer. :grinning_face_with_smiling_eyes:
Can you post your updated code that threw the error?

line 5:

let average (term1+tern2+term3)/3 //SyntaxError: Unexpected '('

should be this:

let average = (term1+term2+term3)/3
            ^

finally line 20 should have two ending parentheses

const finalGrade = (term1, term2, term3) => {

  if ((term1 < 0 || term1 > 100) || (term2 < 0 || term2 > 100) || (term3 < 0 || term3 > 100)){

    return 'You have entered an invalid grade.'

  }

  let average  = (term1 + term2 + term3) / 3

}

  if (average < 100){

      return 'A'

  }   else if (average < 90){

      return 'B'

  }   else if (average <80) {

      return 'C'

  }   else if (average <70) {

      return 'D'

  }   else {

      return 'F'

  }

}

console.log(finalGrade(0, 0, 0))

Yes! Thanks! Bad copying :face_with_hand_over_mouth:

Frequently when you get an error message that seems to make no sense, the issue is with the line of code above the line referenced in the error. The current error I get when running your code is:

/home/ccuser/workspace/sandbox-workspace/index.js:37
console.log(finalGrade(0, 0, 0))
^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

So, you might ask yourself, “Why is console.log() unexpected?” What is the line above it? In this case, it is simply }. So, now the question is does it belong there?

Hint

If the answer is yes (it is), then there must be a stray closing bracket somewhere above it that orphaned this one.

1 Like

You have an extraneous right bracket in your code. Also you have to set a lower bound for all of the conditions except the last or 0, 0, 0 is an A. Try this:

const finalGrade = (term1, term2, term3) => { if ((term1 < 0 || term1 > 100) || (term2 < 0 || term2 > 100) || (term3 < 0 || term3 > 100)){ return 'You have entered an invalid grade.' } let average = (term1 + term2 + term3) / 3 if (average < 100 && average > 90){ return 'A' } else if (average < 90 && average > 80){ return 'B' } else if (average <80 && average > 70) { return 'C' } else if (average <70 && average > 60) { return 'D' } else { return 'F' } } console.log(finalGrade(0, 0, 0)) console.log(finalGrade(78, 82, 94))

Yes! I fixed the errors and looked them all up and you are right! All 0 grades gives an A. Actually , everything below 100 gives an A. I get it. Because everything less than 100 gives a true, so will return an A.

Ah, that euphoric feeling when you get the error of your ways…

Thanks for pointing that out! By changing the order (as shown in Code Solution) this also does not happen anymore.