Can anyone tell me why am failing test 19?
I am getting exactly the results I’m supposed to be getting but it keeps failing the test.
function getAverage(testScoresArr) {
let total = 0;
for (const score of testScoresArr) {
total += score;
}
const average = total / testScoresArr.length;
return average;
};
const average = getAverage([10, 12, 50, 60, 0]);
console.log(average);
console.log();
function getGrade(studentScore) {
let grade = (studentScore === 100) ? “A+”
: (studentScore >= 90) ? "A"
: (studentScore >= 80) ? "B"
: (studentScore >= 70) ? "C"
: (studentScore >= 60) ? "D"
: "F";
return grade;
};
const grade = getGrade(average);
console.log(grade);
console.log();
function hasPassingGrade(grade) {
return grade !== “F”;
};
const pass = hasPassingGrade(grade);
console.log(pass);
console.log();
function studentMsg(classAveragesArr, studentScore) {
let total = 0;
for (const score of classAveragesArr) {
total += score;
}
const classAverage = total / classAveragesArr.length;
let grade = (studentScore === 100) ? “A+”
: (studentScore >= 90) ? "A"
: (studentScore >= 80) ? "B"
: (studentScore >= 70) ? "C"
: (studentScore >= 60) ? "D"
: "F";
if (studentScore >= 60) {
return \`Class average: ${classAverage}. Your grade: ${grade}. You passed the course.\`
}
return `Class average: ${classAverage}. Your grade: ${grade}. You failed the course.`
};
console.log(studentMsg([15, 25, 35, 45, 55, 60, 70, 60], 75));
// running tests
19. Your hasPassingGrade function should return false if the grade is an "F".
// tests completed
// console output
26.4
F
false
Class average: 45.625. Your grade: C. You passed the course.
Please use the Get Help button and than the Ask for Help button inside the challenge you have problem with.
This will make a formatted post with a link to the challenge.
I see. Will do, thank you for your response.
1 Like
Tell us what’s happening:
Not passing test 19 on Building a Gradebook app despite getting the correct results.
Your code so far
function getAverage(testScoresArr) {
let total = 0;
for (const score of testScoresArr) {
total += score;
}
const average = total / testScoresArr.length;
return average;
};
const average = getAverage([99]);
console.log(average);
console.log();
function getGrade(studentScore) {
let grade = (studentScore === 100) ? "A+"
: (studentScore >= 90) ? "A"
: (studentScore >= 80) ? "B"
: (studentScore >= 70) ? "C"
: (studentScore >= 60) ? "D"
: "F";
return grade;
};
const grade = getGrade(average);
console.log(grade);
console.log();
function hasPassingGrade(grade) {
console.log("Grade in hasPassingGrade:", grade); // Debugging
return grade !== "F"; // True if grade isn't "F"
};
const pass = hasPassingGrade(grade);
console.log(pass);
console.log();
function studentMsg(classAveragesArr, studentScore) {
let total = 0;
for (const score of classAveragesArr) {
total += score;
}
const classAverage = total / classAveragesArr.length;
let grade = (studentScore === 100) ? "A+"
: (studentScore >= 90) ? "A"
: (studentScore >= 80) ? "B"
: (studentScore >= 70) ? "C"
: (studentScore >= 60) ? "D"
: "F";
if (studentScore >= 60) {
return `Class average: ${classAverage}. Your grade: ${grade}. You passed the course.`
}
return `Class average: ${classAverage}. Your grade: ${grade}. You failed the course.`
};
console.log(studentMsg([15, 25, 35, 45, 55, 60, 70, 60], 75));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Gradebook App - Build a Gradebook App
I have edited your post to display your code correctly for the forum and also to include a direct link to the challenge.
There are some issues with your code, not least that you have created helper functions (e.g. getGrade) but you’re not calling them inside your studentMsg function. Instead you’re just repeating blocks of code again.
You’re also not quite following the User Stories correctly in some cases, when creating your functions. For instance, your hasPassingGrade function should take a score (not a grade) as a parameter and call on the getGrade function to get the grade, inside the function.
1 Like
Thank you for your response. Even though the result is the same, using the getGrade function in the hasPassingGrade function passed the test.
1 Like