I just need to get over the stupid requirement 22 about student msg and i need to know were to put the fix at
Your code so far
// 1. getAverage function to calculate the average score
function getAverage(scores) {
const total = scores.reduce((acc, score) => acc + score, 0); // sum all scores
return total / scores.length; // divide by the number of scores
}
// 2. getGrade function to return a grade based on score
function getGrade(score) {
if (score === 100) return "A+";
if (score >= 90) return "A";
if (score >= 80) return "B";
if (score >= 70) return "C";
if (score >= 60) return "D";
return "F"; // If score is below 60
}
// 3. hasPassingGrade function to check if a score is a passing grade
function hasPassingGrade(score) {
const grade = getGrade(score);
return grade !== "F"; // Return true if the grade is not "F"
}
// 4. studentMsg function to generate a message for the student
function studentMsg(scores, studentScore) {
const classAverage = getAverage(scores); // Calculate class average
const studentGrade = getGrade(studentScore); // Get the student's grade
const passed = hasPassingGrade(studentScore); // Check if the student passed
// Return the message based on the pass/fail status
if (passed) {
return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You passed the course.`;
} else {
return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You failed the course.`;
}
}
// Example Test Cases
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])); // Should return 71.7
console.log(getGrade(92)); // Should return "A"
console.log(hasPassingGrade(92)); // Should return true
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); // Should return failure message
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)); // Should return success message
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
// 1. getAverage function to calculate the average score
function getAverage(scores) {
const total = scores.reduce((acc, score) => acc + score, 0); // sum all scores
return total / scores.length; // divide by the number of scores
}
// 2. getGrade function to return a grade based on score
function getGrade(score) {
if (score === 100) return "A+";
if (score >= 90) return "A";
if (score >= 80) return "B";
if (score >= 70) return "C";
if (score >= 60) return "D";
return "F"; // If score is below 60
}
// 3. hasPassingGrade function to check if a score is a passing grade
function hasPassingGrade(score) {
const grade = getGrade(score);
return grade !== "F"; // Return true if the grade is not "F"
}
// 4. studentMsg function to generate a message for the student
function studentMsg(scores, studentScore) {
const classAverage = getAverage(scores); // Calculate class average
const studentGrade = getGrade(studentScore); // Get the student's grade
const passed = hasPassingGrade(studentScore); // Check if the student passed
// Return the message based on the pass/fail status
if (passed) {
return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You passed the course.`;
} else {
return `Class average: ${classAverage.toFixed(1)}. Your grade: ${studentGrade}. You failed the course.`;
}
}
// Example Test Cases
console.log(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])); // Should return 71.7
console.log(getGrade(92)); // Should return "A"
console.log(hasPassingGrade(92)); // Should return true
console.log(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)); // Should return failure message
console.log(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)); // Should return success message
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
It is great that you solved the challenge,please don’t post your full working solution.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.