Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Please I don’t understand why my code isn’t passing.. I have tried even using string concatenation to get it but still not passing.. I need help

Your code so far

function getAverage(scores) {
  let sum = 0;

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

  return sum / scores.length;
}

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

function hasPassingGrade(score) {
  return getGrade(score) !== "F";
}


// User Editable Region

function studentMsg(totalScores, studentScore) {
  if (hasPassingGrade ) {
    return "Class average:" + getAverage(totalScores) + "Your grade:" + getGrade(studentScore) + "you passed the course"; 
  }
  else {
    return "Class average:" + getAverage(totalScores) + "Your grade:"+ getGrade(studentScore) + "you failed the course"; 

  }

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

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Linux; U; Android 12; en-ng; CPH2387 Build/SP1A.210812.016) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.98 Mobile Safari/537.36 PHX/16.8

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

If you look at the console, you should see that your function is outputting the following:

Class average:71.7Your grade:Fyou passed the course

Can you see the issue? Your return message should exactly match the requirements.

You could try adding this below your other console.log, for comparison:

// expected output
console.log("Class average: 71.7. Your grade: F. You failed the course.");

NOTE that your first console.log should have a studentScore of 37 (not 89).

Also, for your condition to work, it needs to feed a score as an argument into the function:

if (hasPassingGrade)

This is missing an argument.

Sorry for late response.. although I don’t really understand what you mean.. by what you showed me , I need my concatenation to be done properly right.. and what I found out with the console you showed me.. 71.1 showed the student got an F which is wrong.. so I would try a different stuff then come show you.. thanks

71.1 is the average, not the student score

Well I looked at it.. it seems I got it but the one problem I’m facing right now is the semicolon at the end of the sentence.. I can’t seem to get it right.. maybe I don’t know how to add the semicolon there

  Sorry my bad.. what I wanted to say was a single string at the end of the sentence

Never mind I solved it.. thanks for your assistance..

1 Like

how??
i’m stuck here too

hi @naveedlatifccw113

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

What is the problem with your code.. paste it here

I posted and someone gave me solution. it’s solved thanks.