function orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(11);
orderMyLogic(4);
orderMyLogic(6);
// running tests
orderMyLogic(4) should return “Less than 5”
// tests completed
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.
Correctly, but when (val < 10) is not true? When val is equal or bigger than 10, which means it is also bigger than 5. Thus, (val < 5) will never be true.
function orderMyLogic(val) { // START - val is 4 for example
if (val < 10) { // ok first we evaluate this, val < 10 ? yes! enter the conditional
return "Less than 10"; // END - return "Less than 10"
} else if (val < 5) { // the code doesn't even reach here because we already returned from the function
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}