Created
July 5, 2022 05:52
-
-
Save detkno90/f32e361728d0e4abe29972c45f287546 to your computer and use it in GitHub Desktop.
challenge project :finalGrade()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Write a function, finalGrade(). It should: | |
take three arguments of type number | |
find the average of those three numbers | |
return the letter grade (as a string) that the average corresponds to | |
return ‘You have entered an invalid grade.’ if any of the three grades are less than 0 or greater than 100 | |
0-59 should return: 'F' | |
60-69 should return: 'D' | |
70-79 should return: 'C' | |
80-89 should return: 'B' | |
90-100 should return: 'A'## | |
// solution ___ // | |
// Write your function here: | |
const finalGrade = (aA,bB,cC) => { | |
if((aA < 0 || aA >100) || (bB < 0 || bB > 100) || (cC < 0 || cC > 100 )) | |
{return'You have entered an invalid grade.'; | |
} | |
let average = (aA + bB + cC) / 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 if (average < 100){ | |
return 'A' | |
} | |
}; | |
// Uncomment the line below when you're ready to try out your function | |
console.log(finalGrade(99, 100, 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