Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

what’s wrong with this I’m stuck here for 3 hours. I tried everything I knew

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 (studentMsg) {
      return "Class average: " + getAverage(totalScores) + ". Your grade: " + hasPassingGrade(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));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));

// 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/125.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

how do you expect studentMsg here to change between a falsy and truthy value?

do you have a different way to determine if the student failed or passed?

I tried to put ==hasPassingGrade(studentScore),== getGrade(studentScore).What i should put in parametr?

would those be comparisons with studentMsg? Do not use studentMsg in the condition at all, it’s the function you are writing

it could work, but you need to know: what does hasPassingGrade return?

it could work, but you need to know: what does getGrade return?

hasPassingGrade return a false when function getGrade give F.In another case return true

that seems pretty promising to use for your if condition, why don’t you try?

I tried it and it didn’t work.I don’t know what wrong

show your code please

``
function studentMsg(totalScores, studentScore) {

if (studentMsg == hasPassingGrade(studentScore)) {
return "Class average: " + getAverage(totalScores) + “. Your grade: " + hasPassingGrade(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));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
``
what wrong

didn’t I tell you something about studentMsg in the condition?
it’s a function, you can’t compare it with a boolean value

function studentMsg(totalScores, studentScore) {

if (hasPassingGrade(studentScore)) {
      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([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// running tests Your function call of

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

should return the following message:

"Class average: 71.7. Your grade: F. You failed the course."

. Your function call of

studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)

should return the following message:

"Class average: 50.8. Your grade: A++. You passed the course."

. Your

studentMsg

function should return the correct message based on the student’s score and the class average.
// tests completed
// console output
Class average: 50.8. Your grade: A++ You passed the course
Class average: 71.7. Your grade: F You failed the course.

what wrong now?

Let’s add

console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
console.log("Class average: 50.8. Your grade: A++. You passed the course.")

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log("Class average: 71.7. Your grade: F. You failed the course.");

Which gives this output:

Class average: 50.8. Your grade: A++ You passed the course
Class average: 50.8. Your grade: A++. You passed the course.
Class average: 71.7. Your grade: F You failed the course.
Class average: 71.7. Your grade: F. You failed the course.

it looks like you are missing a period after the grade.

PASS!!! i need 3 dots…

function studentMsg(totalScores, studentScore) {
const classAverage = getAverage(totalScores).toFixed(1);
const studentGrade = getGrade(studentScore);
const passed = hasPassingGrade(studentScore);

if (passed) {
return "Class average: " + classAverage + ". Your grade: " + studentGrade + “. You passed the course.”;
} else {
return "Class average: " + classAverage + ". Your grade: " + studentGrade + “. You failed the course.”;
}
}

console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
i ain’t seeing the problem on my code above but i keep receiving the following comment;
// running tests Your

studentMsg

function should return the correct message based on the student’s score and the class average. // tests completed // console output Class average: 71.7. Your grade: F. You failed the course.

hey @Sharon , it’s best if you open your own topic to ask for help. But anyway, do not round.

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 Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for 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.

im having trouble with this too. i used chat gpt and nothing will work.

Open a new topic please, and don’t use chatgpt to learn coding.

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 Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for 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.

1 Like