Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 27, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/00b60c92f6ab07112587c1977bd8aceb to your computer and use it in GitHub Desktop.
Save codecademydev/00b60c92f6ab07112587c1977bd8aceb to your computer and use it in GitHub Desktop.
Codecademy export
// Write your function here:
// function
const sumOfFinalGrade = (test, homework, exam) => {
// if (test < 0 || test > 100 || homework < 0 || homework > 100 || exam < 0 || exam > 100){
// return 'You have entered an invalid grade.';
// }
return test + homework + exam;
};
// function
const finalGrade = (test, homework, exam) => {
if (test < 0 || test > 100 || homework < 0 || homework > 100 || exam < 0 || exam > 100){
return 'You have entered an invalid grade.';
}
const average = sumOfFinalGrade(test, homework, exam) / 3;
if (average <= 59) {
return 'F'
} else if (average <= 69) {
return 'D'
} else if (average <= 79) {
return 'C'
} else if (average <= 89) {
return 'B'
} else if (average <= 100) {
return 'A'
}
};
// output
console.log(finalGrade(-1, 92, 95))
// Uncomment the line below when you're ready to try out your function
console.log(finalGrade(-1, 92, 95)) // Should print 'A'
// We encourage you to add more function calls of your own to test your code!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment