JavaScript finalGrade exercise

JavaScript FinalGrade Exercise

Hello everyone hope you are all enjoying your weekend.

I am having a lot of troubles with this very simple exercise, because… I don’t know. When I run it gives me no errors, it gives me all the grades and if it’s outside of 0 or 100 it says invalid but I still get this message

Blockquote If any of the grades passed in are less than 0 or greater than 100, the function should return ‘You have entered an invalid grade’

HELP please!!

Thank you for sharing your code :slight_smile: really helpful, could you please also share exercise url? This enables us to run your code in the lesson.

Thank you for answering me on a Saturday,

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/code-challenge-javascript-fundamentals/lessons/javascript-fundamentals-code-challenge/exercises/final-grade

const finalGrade = (midterm, final, homework) => {
    if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100)) {
        return 'You have entered an invalid grade.'
    }
    let average = (midterm + final + homework) / 3
    if (average < 60) {
        return 'F'
    }
    else if (average < 70) {
        return 'D'
    }
    else if (average < 80) {
        return 'C'
    }
    else if (average < 90) {
        return 'B'
    } else {
        return 'A'
    }
}

/*
//as a function declaration:
function finalGrade(midterm, final, homework) {
    if ((midterm < 0 || midterm > 100) || (final < 0 || final > 100) || (homework < 0 || homework > 100)) {
        return 'You have entered an invalid grade.'
    }
    let average = (midterm + final + homework) / 3
    if (average < 60) {
        return 'F'
    }
    else if (average < 70) {
        return 'D'
    }
    else if (average < 80) {
        return 'C'
    }
    else if (average < 90) {
        return 'B'
    } else {
        return 'A'
    }
}
*/

strings returned need to be an exact match, so copy this:

'You have entered an invalid grade.'

from the instructions.

OMG!!! my brain was about to explode.

Thank you so so much!!

2 Likes