function orderMyLogic(val) {
if (val > 5 && val < 10) {
return “Less than 10”;
} else if (val > 1 && val < 5) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}
}
function orderMyLogic(val) {
if (val < 5) {
return “Less than 5”;
} else if (val < 10 ) {
return “Less than 10”;
} else {
return “Greater than or equal to 10”;
}
}
the problem is the order of the code, hence what the whole chapter is about. when it tests if 4 is less than 10 the first time it is true, so it doesnt continue in the else statements. reorder the code so that it tests if 4 is less than 5 first.
My solution for this problem. We can use && operator in the first ‘if’ statement
function orderMyLogic(val) {
if (val < 10 && val > 5) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}