- Go to the problem.
- Reset the page to make sure the page is set up by default.
- Press run the code.
- You will find the following console log statements.
// running tests
1. 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."
.2. 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."
3. Your studentMsg function should return the correct message based on the student's score and the class average. // tests completed // console output undefined
To start, the step 4 just give you one studentMsg console.log.
That is: console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
The second studenMsg console.log isn’t provided by the exercise but its requested after you try to run the code.
Its missing: console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
After doing the code right what i consider being correct, as what were requested, it continue saying that something its not right. The only thing that i could not did is include " to show in my final console.log statement, im not sure that this might be the error.
Is the exercise with a bug?
Following, my whole code:
Observation: I have added manually the second missing and requested console.log statement in my code example, which is:
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));
My final console.log answer is:
Class average: 71.7.Your grade: F.You failed the course.
Class average: 50.8.Your grade: A++.You passed the course.
Not a big deal exercise, but any help is well appreciated as if its indeed a bug, hope i have contributed for something.
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) {
if (getGrade(studentScore) !== "F") {
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));
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100));