I fixed the error and added the semicolon it asked for, but why is the semicolon necessary in the “else if chain” and after the parentheses of all places?
Thanks in advance.
Your code so far
function testSize(num) {
// Only change code below this line
if (num < 5) {
return "Tiny";
} else if (num < 10) {
return "Small";
} else if (num < 15) {
return "Medium";
} else if (num < 20) {
return "Large";
} else (num >= 20); {
return "Huge";
}
return "Change Me";
// Only change code above this line
}
testSize(7);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0
Challenge: Basic JavaScript - Chaining If Else Statements
the function goes down the whole chain of if else statements, this is the last in the chain. If the number is greater or equal than 20, it returns a value of “Huge”.
I’m not sure why it won’t function without the semicolon after the brackets though. Do you?
well I just noticed one thing that is not there, (condition4) to match statement4. And thats fine.
was it unecessary to give that parameter to my else statment? Meaning was (num >= 20) one of my errors? Could I have simply wrote:
} else {
return "Huge";
}
Edit: I ran the test using the above. It worked.
So with my previous “solution”, it seemed to have worked but was poorly written code. By removing the final parameter I would have had a much better solution.
It’s still strange that a semicolon made it function.