Build a Gradebook App

Tell us what’s happening:

I can’t pass Step 19. Your hasPassingGrade function should return false if the grade is an "F". I’ve tried logging the function’s result in the console to make sure it’s returning the right output from the appropriate value. I couldn’t pass the tests involving this function so I’ve tried simplifying it to its current state but I still can’t pass Step 19.

Your code so far

function getAverage(scoresArray){
  let average = scoresArray.reduce((total, value) => total+value) / scoresArray.length;
  return average;
}

function getGrade(score){
  if(score == 100){
    return "A+";
  } else if(score <= 99 && score >= 90){
    return "A";
  } else if(score <= 89 && score >= 80){
    return "B";
  } else if(score <= 79 && score >= 70){
    return "C";
  } else if(score <= 69 && score >= 60){
    return "D";
  } else if(score <= 59){
    return "F";
  }
}

function hasPassingGrade(letterGrade){
  if(letterGrade === "F"){
    return false;
  } else {
    return true;
}

function studentMsg(scoresArray, studentScore){
  switch(hasPassingGrade(getGrade(studentScore))){
    case true: return `Class average: ${getAverage(scoresArray)}. Your grade: ${getGrade(studentScore)}. You passed the course.`;
    break;
    case false: return `Class average: ${getAverage(scoresArray)}. Your grade: ${getGrade(studentScore)}. You failed the course.`;
    break;
  }
}

let letterGrade = getGrade(0);
console.log(`Letter grade: ${letterGrade}`);
console.log(`Passed: ${hasPassingGrade(letterGrade)}`);

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

Your browser information:

User agent is: ‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36’

Challenge Information:

Build a Gradebook App

Welcome to the forum @06OldManJustin21

Do you see a message in the console?

SyntaxError: unknown: Unexpected token (42:71)

  40 | console.log(`Passed: ${hasPassingGrade(letterGrade)}`);
  41 |
> 42 | console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
     |                                                                        ^

Happy coding

1 Like

Thank you for your reply and warm welcome.

I actually don’t see an error message for that. I haven’t changed that part of the code and this is what it shows me.

The hasPassingGrade function should use the getGrade function to get the letter grade

Does your code do this from User Story 4? And you are missing a curly brace in that function.

Yes. The only test it’s not passing is number 19.

This code is different than what you posted originally. A missing curly brace in the hasPassingGrade function caused the syntax error in the console.

You are not passing score as a parameter to hasPassingGrade() and you are not using getGrade() inside the function to get the letter grade.

1 Like

Thank you so much! :heart_on_fire: :heart_on_fire: :heart_on_fire: :heart_on_fire: :heart_on_fire: