Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

function studentMsg(totalScores, studentScore) { 
  while (getGrade(studentScore)==="F"){
return '"'+'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You failed the course.' + '"';
}return '"'+'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You passed the course.' + '"';
}

I am getting the same result at step 4 still it isn’t getting completed.
Why it isn’t getting completed . Frustrating !!!

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) { 
  while (getGrade(studentScore)==="F"){
return '"'+'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You failed the course.' + '"';
}return '"'+'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You passed 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

You shouldn’t be adding quotation marks inside of your strings

Code is incorrect:

  • Don’t use while loop. Use if/else statement instead.
  • Don’t use quotes at beginning and ending of the returning string ‘"’.
  • Use proper spacing after periods and colons.

Actually I have tried every permutation possible and was just trying to match the exact result . This gives the exact result with proper colon and spacing . You can try it yourself.
But it is not getting completed

We don’t need to throw everything all at once

No, that is not correct. You absolutely must not add in the quotation marks as part of the returned string. They cannot be there.

The parts like this have to go

It is specifically asking to return a string like this
“Class average: 71.7. Your grade: F. You failed the course.”
So I have added these and I have ran the program without Quotation marks also but to no avail.

Yes, they are showing you what should be the output string. But those quotes should not be inside of the string. Quotes show that the thing being returned is a string.

So, what does your code look like without those extra quotes thrown in?

They don’t do anything unexpectedly.

Result syntax is same just without quotes if you remove it .

I have added them bcoz my code was not getting passed so I just want to replicate the exact result so I added them

Please show your code without those quotes

function studentMsg(totalScores, studentScore) { 
  while (getGrade(studentScore)==="F"){
return 'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You failed the course.' ;
}return +'Class average:' + getAverage(totalScores) +'. ' +'Your Grade:' +' ' + getGrade(studentScore)+ '. You passed the course.' ;
}

Without quotes

Ok, now double check the spelling here

Gotcha sir thanks for help.

Why I always mess up the semantics and definition which eventually turns the whole logic and effort futile.

Any insight to recity these small mistakes and save myself getting messed up

Thanks

Lots and lots of practice, honestly. Developers make mistakes - its part of the process

If your code works, I’d go ahead and replace this while with an if now. while is for when you want to repeat something multiple times.

Definitely sir and while can get stuck indefinitely

Code is still not accepted . Stuck there

Did you fix the capitalization? What is your full current code?

“Class average: 71.7. Your grade: F. You failed the course.”
This needs to be printed.

while (getGrade(studentScore)==="F"){

return '"'+'Class average:'+' ' + getAverage(totalScores) +'. ' +'Your grade:' +' ' + getGrade(studentScore)+ '. You failed the course.' + '"';

}return '"'+'Class average:' + getAverage(totalScores) +'. ' +'Your grade:' +' ' + getGrade(studentScore)+ '. You passed the course.' + '"';
}

This is my code

Complete the studentMsg function with totalScores and studentScore for parameters. The function should return a string representing a message to the student.

This is the problem description which wants to return a STRING

Change while to the if, then check the spacing and punctuation within both returning strings.