Tell us what’s happening:
why is there two } at the end of the first else statement ?
**Your code so far**
function testElseIf(val) {
if (val > 10) {
return "Greater than 10";
}
else if (val < 5) {
return "Smaller than 5";
} else{
}
return "Between 5 and 10";
}
testElseIf(7);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49
Challenge: Basic JavaScript - Introducing Else If Statements
Link to the challenge:
Let’s apply some formatting
function testElseIf(val) {
if (val > 10) {
return "Greater than 10";
} else if (val < 5) {
return "Smaller than 5";
} else {
}
// Either this sholud be inside the else, or the else shouldn't be there
return "Between 5 and 10";
}
The last } is closing the function the one before it is closing the else
As said, an empty else block doesn’t really make much sense.
Thank you very much. Would learning algo help me witb the structure and syntax?
system
Closed
January 12, 2023, 1:43pm
5
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.