Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Tell us what’s happening:

Here is my code:

function getGrade(score) {
if (score === 100) {
return “A++”;
} else if (score >= 90 && score < 100) {
return “A”;
} else if (score >= 80 && score < 90) {
return “B”;
} else if (score >= 70 && score < 80) {
return “C”;
} else if (score >= 60 && score < 70) {
return “D”;
} else if (score >= 0 && score < 60) {
return “F”;
} else {
return “Invalid score”;
}
}

Where am I going wrong?

Your code so far

function getAverage(scores) {
  let sum = 0;

  for (const score of scores) {
    sum += score;
  }

  return sum / scores.length;
}

// User Editable Region

function getGrade(score) {
    if (score === 100) {
        return "A++";
    } else if (score >= 90 && score < 100) {
        return "A";
    } else if (score >= 80 && score < 90) {
        return "B";
    } else if (score >= 70 && score < 80) {
        return "C";
    } else if (score >= 60 && score < 70) {
        return "D";
    } else if (score >= 0 && score < 60) {
        return "F";
    } else {
        return "Invalid score";
    }
}

console.log(getgrade(100))
console.log(getGrade(96));
console.log(getGrade(82));
console.log(getGrade(56));

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 2

Can you say more about how you are confused by the problem or error message? Communication is a critical programming skill

I can’t seem to get “Your getGrade function should return "A++" if the score is 100 .” to work? Sorrry

Hmm, something is fishy with this line. How is that function name capitalized?

What does it return?

Can you talk about the tests you’ve done, and the output of the program?

As has already been said there is an issue with the inside of the console.log statements (why change what was already there?). Also you have not been asked to check for an invalid score. And, although it may still pass, you do not need two conditions in each else if expression.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.