I am passing all the checks other than test 17. I am getting the correct result out of the function but for some reason unbeknownst to me, the function doesn’t pass.
Maybe a small typo or what can it be?!
Your code so far
// Get in the array and return the average of sum
function getAverage (array) {
let result = 0;
for(let num of array) {
result += num;
}
return result / array.length;
}
// pass in the score and check what grade it is
function getGrade (int) {
if(int === 100) {
return "A+"
} else if(int >= 90) {
return "A"
} else if (int >= 80) {
return "B";
} else if (int >= 70) {
return "C";
} else if(int >= 60) {
return "D"
} else {
return "F"
}
}
// Checks if getGrade function result is a passing grade
function hasPassingGrade (score) {
return score !== "F" ? true : false;
}
// Show message to user if the grade is passable or not
function studentMsg (arrayScores, studentScore) {
let averageScore = getAverage(arrayScores);
let yourGrade = getGrade(studentScore);
let passingGrade = hasPassingGrade(yourGrade);
if(passingGrade) {
return `Class average: ${averageScore}. Your grade: ${yourGrade}. You passed the course.`;
} else {
return `Class average: ${averageScore}. Your grade: ${yourGrade}. You failed the course.`;
}
}
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 60));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
You should have a function named hasPassingGrade that takes a score as a parameter and returns either true or false depending on if the score corresponds to a passing grade.
The hasPassingGrade function should use the getGrade function to get the letter grade, and use it to determine if the grade is passing. A passing grade is anything different from "F".
hi @yehaigithub please create your own topic to ask your own questions
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.