Review JavaScript Fundamentals by Building a Gradebook App - Step 4

Tell us what’s happening:

Hey there! i´m just me again hahah. i have a problem and i don´t find the error. i did it step by step but the error stays.
Somebody can help me?

Your code so far


// User Editable Region

function getAverage(scores) {
    if (scores.length === 0) {
        return 0.0; // Ensure correct formatting for empty array
    }
    
    let total = scores.reduce((sum, score) => sum + score, 0);
    return parseFloat((total / scores.length).toFixed(1)); // Ensure one decimal place and convert to number
}

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) {
    let classAverage = getAverage(totalScores).toFixed(1); // Ensure consistent decimal formatting
    let studentGrade = getGrade(studentScore);
    let status = hasPassingGrade(studentScore) ? "passed" : "failed";
    
    return `Class average: ${classAverage}. Your grade: ${studentGrade}. You ${status} the course.`;
}

// Test cases
console.log(getAverage([80, 90, 100])); // Expected output: 90.0
console.log(getAverage([50, 60, 70, 80])); // Expected output: 65.0
console.log(getAverage([])); // Expected output: 0.0

console.log(getGrade(100)); // Expected output: "A++"
console.log(getGrade(95));  // Expected output: "A"
console.log(getGrade(85));  // Expected output: "B"
console.log(getGrade(75));  // Expected output: "C"
console.log(getGrade(65));  // Expected output: "D"
console.log(getGrade(50));  // Expected output: "F"

console.log(hasPassingGrade(100)); // Expected output: true
console.log(hasPassingGrade(75));  // Expected output: true
console.log(hasPassingGrade(50));  // Expected output: false

console.log(studentMsg([80, 90, 100], 85)); // Expected output: "Class average: 90.0. Your grade: B. You passed the course."
console.log(studentMsg([50, 60, 70, 80], 50)); // Expected output: "Class average: 65.0. Your grade: F. You failed the course."


// User Editable Region


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0

Challenge Information:

Review JavaScript Fundamentals by Building a Gradebook App - Step 4

What error are you getting? Is there any hints or feedback?

Can you say what you’ve already tried to solve it?

Have you compared the output of your function to make sure it’s the same as what’s required? Can you please show the comparison?

Hey! Well the error that i´m getting is:
// running tests
3. Your studentMsg function should return the correct message based on the student’s score and the class average.
// tests completed
// console output
it try to solve it as follows

  1. Ensured class average formatting:
  • Used .toFixed(1) to keep one decimal place.
  • Converted toFixed(1) output back to a number using parseFloat() to avoid string mismatches.
  1. Checked for formatting errors in studentMsg():
  • Verified punctuation and spacing match expected output exactly.
  • Ensured correct concatenation of variables in the return statement.
  1. Checked edge cases in getAverage():
  • Ensured an empty array returns 0.0 instead of 0 for consistency.
  • Used reduce() correctly to sum values.
  1. Validated getGrade() and hasPassingGrade():
  • Checked grade logic to confirm proper letter assignment.
  • Ensured "F" is the only failing grade.

Current Console Output:

vbnet

Class average: 90.0. Your grade: B. You passed the course.
Class average: 65.0. Your grade: F. You failed the course.

Expected Output (from my test system):

Class average: 90. Your grade: B. You passed the course.
Class average: 65. Your grade: F. You failed the course.

Key Difference:

  • Our output includes .0 in 90.0 and 65.0, while the expected output does not.
  • The test expects whole numbers without decimals when applicable.

Please don’t use AI replies. What is vbnet ?

Do you know if the test would be expecting 72 or 72.0? This 1 decimal place is not written as a requirement.

console.log(studentMsg([95, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37));
Class average: 72.0. Your grade: F. You failed the course.

Did an AI tool suggest that you add this?

It seems like you already have the solution here?

Don’t use AI to solve these, obviously it’s not helping you learn.

3 Likes

you´re right. i´m sorry It’s an impulse I have most of the time hahaha

Please note that having AI write your code for you is a violation of the freeCodeCamp academic honesty pledge.

https://www.freecodecamp.org/news/academic-honesty-policy/

It also will not strengthen your code writing muscles.

posting AI generated content is also a violation of the rules of this forum

https://forum.freecodecamp.org/guidelines