Shouldn’t this technically work? I mean, I understand that the solution removes some extra code taking the line “else if (val >= 5 && val <=10 )” out and replacing it with “else { return “Between 5 and 10” }”
I just want to make sure I totally understand the & operator.
**Your code so far**
function testElseIf(val) {
if (val > 10) {
return "Greater than 10";
}
else if (val < 5) {
return "Smaller than 5";
}
else if (val >= 5 && <= 10) {
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/101.0.4951.64 Safari/537.36 Edg/101.0.1210.47
For the last condition, remove the else if (val >= 5 && <= 10) and replace it with just else. This is because it’s the last condition and it will always be true if the previous ones are false (assuming that val is always a number)
Thank you - it’s nice to understand WHY they wanted me to do it that certain way. It didn’t explain in the challenge, and technically my way would have worked (val >= 5 && val <=10) is “between 5 and 10” right?