Error? Missing close bracket

Help please I’m stuck, I’m so bad at this…

// Write your function here:

const finalGrade = (number1, number2, number3) => {
  if ((number1 < 0 || number1 > 100) || (number2 < 0 || number2 > 100) || (number3 < 0 || number3 > 100)) {
    return 'You have entered an invalid grade';
  } 
}

let average = (number1 + number2 + number3) / 3;

if (average >= 0 || average <= 59) {
  return 'F';
} else if (average >= 60 || average <= 69) {
  return 'D';
} else if (average >= 70 || average <= 79) {
  return 'C';
} else if (average >= 80 || average <= 89) {
  return 'B';
} else if (average >= 90 || average <= 100) {
  return 'A';
}

console.log(finalGrade(60, 70, 75))

Shows an error saying number1 is not defined.

Hint: Did you close your function body ahead of the critical code?

I believe so…:sweat::sweat: can you help me please

Locate the RBRACE (right curly brace) that closes your finalGrade function and move it to just above the last line where you log the result. That way all the critical code will be inside the function body, rather than out in space.

1 Like

Oh my god… thank you

1 Like

You’re welcome. It’s an easy mistake to make; and one to learn from.

Tip

Block out the code so all the bodies are visible…

const finalGrade () => {
  //
};

then,

const finalGrade () => {
  if () {
    return  // error
  }
  let average; // = ...
  if () {
    return  // letter
  }
  // remaining else if blocks
};

The code won’t run, of course, but we can fill in the blanks and be better assured that our syntax and structure is correct, or nearly so. I like to call it scaffolding or blocking where both terms are synonymous in this respect. We start with a sketch, then begin shading.

1 Like