Tell us what’s happening:
The studentMsg() function example logic is flawed. Expected Result:
- 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.”
The average of the array argument 71.7, is not an F or failing. The argument 37, is an F and is failing but it is not the average. The message becomes nonsense. By calling the other functions from within studentMsg() you can get the CORRECT results from just the array. The message should say: “Class average: 71.7. Your grade: C. You passed the course.”
22-26 all have the same logic issues.
My code passes, but the logic is flawed. I commented out the way I would solve this if the logic was correct.
Your code so far
function getAverage(testScores){
let total = 0;
for (const score of testScores){
total += score;
}
let average = total/testScores.length;
return average;
}
function getGrade(score){
let letterGrade = "";
if (score >= 100){letterGrade = "A+"}
else if (score >= 90){letterGrade = "A"}
else if (score >= 80){letterGrade = "B"}
else if (score >= 70){letterGrade = "C"}
else if (score >= 60){letterGrade = "D"}
else {letterGrade = "F"}
return letterGrade;
}
function hasPassingGrade(score){
return (!(getGrade(score) == "F"));
}
//function studentMsg(testScores){
function studentMsg(testScores,score){
let message = ""
let passmessage = ""
//if (hasPassingGrade(getAverage(testScores)))
if (hasPassingGrade(score))
{passmessage = "You passed the course."}
else
{passmessage = "You failed the course."}
//message = `Class average: ${getAverage(testScores)}. Your grade: ${getGrade(getAverage(testScores))}. ${passmessage}`;
message = `Class average: ${getAverage(testScores)}. Your grade: ${getGrade(score)}. ${passmessage}`;
return message;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Challenge Information:
Build a Gradebook App - Build a Gradebook App