Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/main.js Secret

Created Aug 4, 2020
Embed
What would you like to do?
Codecademy export
// Write your function here:
const finalGrade = (a, b, c) => {
const sum = a + b + c;
const avg = sum / 3;
if ((a < 0 || a > 100)
|| (b < 0 || b > 100)
|| (c < 0 || c > 100)) {
return 'You have entered an invalid grade.';
}
switch (true) {
case (avg < 60):
return 'F';
break;
case (avg < 70):
return 'D';
break;
case (avg < 80):
return 'C';
break;
case (avg < 90):
return 'B';
break;
default:
return 'A';
break;
}
};
console.log(finalGrade(60,100,80));
// ----------------version1---------------------------
// const passToFunction = () => {
// arrayToPass = [1, 2, 3];
// return finalGrade.apply(null, arrayToPass);
// };
// const finalGrade = (numb1, numb2, numb3) => {
// var sum = numb1 + numb2 + numb3;
// var avg = sum/3;
// return avg;
// };
// console.log(passToFunction());
// // console.log(finalGrade(1,2,3));
//---------------------------------------------------
// Uncomment the line below when you're ready to try out your function
// console.log(finalGrade(99, 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
You can’t perform that action at this time.