Tell us what’s happening:
I’m confused at why this code doesn’t work since it returns the exact characters that it’s supposed to every time.
Your code so far
function getAverage(scores) {
let sum = 0;
for (const score of scores) {
sum += score;
}
return sum / scores.length;
}
// User Editable Region
function getGrade(score) {
if( score === 100) {
console.log("A++");
} else if (score >= 90 && score <= 99) {
console.log("A");
} else if (score >= 80 && score <= 89) {
console.log("B");
} else if (score >= 70 && score <= 79) {
console.log("C")
} else if (score >= 60 && score <= 69) {
console.log("D")
} else if (score < 60) {
console.log("F")
}
return score;
}
console.log(getGrade(94));
console.log(getGrade(82));
console.log(getGrade(56));
// 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/124.0.0.0 Safari/537.36
Challenge Information:
Review JavaScript Fundamentals by Building a Gradebook App - Step 2
What does it actually return though? Logging something doesn’t return anything
I’m not sure what that picture means. My statement above is still true. Logging something to the console doesn’t actually return
anything. What is supposed to be returned?
So in the right of the picture it outputs the required character and then the value for scores that was inputed for example the console outputs:
A
96
I thought all I had to do was log the Character/ Grade for the given percentage?
Do the instructions say to print the letter grade to the console or to return the letter grade?
would that mean I have to create another variable to store the character value and then return that? And are the conditions for the if and else if statements correct?
Can you answer the question please so we are on the same page? Do the instructions ask you to console log or return the letter grade strings?
So sorry, I thought that was a rhetorical question. lol, it asks to return the letter grade strings
Cool. So have you tried swapping out your console log statements for return statements?
Woooow, I always thought that putting return would cancel the rest of the code, but I guess I forgot that that depends on scope. Thanks
1 Like
It does prevent the rest of the code from running though if you are in a case where the return occurs
1 Like
system
Closed
January 1, 2025, 4:16pm
13
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.