Review JavaScript Fundamentals by Building a Gradebook App Step 4


First I tried first one I get result what test ask me, but still not proved as pass. After I tried what console ask me to find about others results. I thought I found them too but still not proved as pass? I dont understand what should I do more? But I know that some thing missing or wrong what I have worked on but I m not sure what… Maybe result is not seems to me as a whole string. Could somebody help me please?

1 Like

Please post your code, not a screenshot. It’s really hard to debug a screenshot

1 Like

First one this one:

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. "
 }  return studentMsg 
 };
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

second one this:

function studentMsg(totalScores, studentScore) {
 if (hasPassingGrade(studentScore)) {
   return console.log("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. "
 }  return studentMsg 
 };
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

When you ask for help, please provide also the link to step, even better use the Ask for help button!


first one,

You have extra space at the end. Spaces are characters, when strings are compared, they can make all the difference.


second one

  • do not return console.log, you are returning undefined here
  • the return studentMsg at the end will never be reached as it is after return statements
  • You have the same issue of an extra space at the end

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([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

Tell us what’s happening:

Console give the result that test asked. I tired many different ways before, but not proved. Could someone tell me what I m doing wrong in here?

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(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([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

You have an extra space at the end, remove the extra space at the end of the strings

I did it but still not working

Also you have missing full stop after " + getAverage(totalScores) + " in both return statements. And same for " + getGrade(studentScore) + ".
@MartyGrass

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([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));

Hi @MartyGrass

I formatted your code so it it more accessible to the forum.

Great job including the punctuation.

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." .

Carefully check the console message to find the casing issue.

Happy coding

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 tried a both as a console message here is return

Class Average: 71.7. Your grade: F. You failed the course.

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

Function is working but test not proving

One of your words needs to be lower case.

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.”.toLowerCase()
}
};

Here is the console return (I tired more but only one of them)

Class Average: 71.7. Your grade: F. you failed the course.

just accepts not capital

The function works. It’s one of the the strings.

Copy the expected output and paste into the editor.
Then copy your output and paste it directly below the first line.

You will need to place two forward slashes at the begging of each line to make the code into a comment.

I copied the expected output : “Class average: 71.7. Your grade: F. You failed the course.” and paste into the editor. Then I copied output from console and paste below the first line with " " . Still function works put test not proved. I already try to placed " " to begining and at the end of the result because maybe test accepts us directly with " " to show the case is strictly string . But should we do it different with another way, cause most of the time " " at the test tips" use " " just clear that its string, not expect " " it should be always there…

there is a difference between your output and the expected one. Remember that case matters

2 Likes

2 posts were split to a new topic: Need help understanding the extra function calls in step 4 grade book app

@MartyGrass and @ilenia ,
your conversation was very benefit for me ,
I am also done with grade book app.