Step 4 Review JavaScript Fundamentals by Building a Gradebook App

I am seeing this in mt code as well as the console messages:
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."

My issue is that the array has the expected 10 items there is a trailing “, 37” after the last array element. Is it an expected item that I just haven’t figured out? Thanks.

Take a look at the definition of the studentMsg function:

studentMsg(totalScores, studentScore)

The studentMsg takes 2 arguments:

  • totalScores is an array of the scores of all students in the class. We use this array to calculate the average score of the class
  • studentScore is the student’s score. We use this argument to check if the student passed or failed the course.

In this case, 37 is studentScore.

If you’re stuck with this step, please post your code so we could help.

OK, I thought it was a single students test scores for a course. Then averaged for a students overall score which will be Pass or Fail. I’ll reread what you gave me and figure this out.

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”;
}

function studentMsg(totalScores, studentScore) {
let studentAverage = getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]);
console.log(studentAverage);
let studentGrade = getGrade(studentAverage);
console.log(studentGrade);
return (“Class average: “studentAverage”. Your grade: “studentGrade”. You passed the course.”);
}
getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]);
getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]);
getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100]);

don’t do this, it will work for only one case, use the function parameters

don’t do this either, the grade should come from the student score, not the class average

Now, I wonder does the actual student have a score within the array we are working with. I assume each array element data is an actual student. We have no student name to work with, so we’ll just parse the array, start to end. Each array element will be run through the getGrade function, which will return a grade for array[0]…array[9], where each of those will go through Pass/Fail function and the actual concatenation work is done and reported to each actual student
array[0]…array[9] .
/* This reminds me of trying to understand what the engineers want to do. Yet there is no documentation. So they write things like this step 4 which no one can grasp without team meeting.*/
Thank you, I look forward to your reply.

no, you use the array just to get the class average
it’s the second argument, the studentScore, that you need a grade for and to say if it passed or not

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