I made one change t
unction 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(4);
I don’t see anything wrong with code
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(4);
this wha they want me to change
orderMyLogic(4) should return “Less than 5” i still don’t understand what you are saying
Your conditional logic fails, once the first condition is met, is true, that’s where the code stops. And the first condition that is true in your code is 4 < 10, your second is 4 < 5 but since the first one is met that’s where the code stops.
I understand but the instruction says others wise.
this below is the only question that was asked of me
orderMyLogic(4) should return “Less than 5” I know the code stope 4< 10 was true but i don’t know what to because my test is failing
<!------Below the were changed in green by defailt------------------------------------------------
//orderMyLogic(6) should return "Less than 10"
//orderMyLogic(11) should return "Greater than or equal to 10"
<_________________________________________________________
When you have an if statement, and its condition is true (For example your first if condition will be true with a input of 4 for val)… Then the program will go inside of that if statement. once if finishes inside of that if statement it will exit. any else if or else are considered to be apart of that first if…
As @Nepherius pointed out, the syntax of your code is correct, but logic is not. The order of when the If statements are executed needs to be changed so that you are not missing potentially valid conditions.
I still don’t understand when i’m just following the examples
I changed one
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(4);
Still getting error
“else if”, is not a separate “if statement”. “else if” is a part of the “if statement” above it… The “else if” condition will only be checked if the previous “if statement” is false.
so. if the first “if” is false, then it will check the next “else / else if”, and if that is false then it will check the one after that(and so on). But if the first “if” is true, it will not check any of the other “else / else if statements” that are after it.
this their code
unction 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(7);
The instructions state to change orderLogic(7)
see the question below
orderMyLogic(4) should return "Less than 5"
here is the link
function orderMyLogic(val) {
if (val < 5) {
return “Less than 10”;
} else if (val < 10) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}
}
// Change this value to test
orderMyLogic(4);
this is wrong even when put orderLylogic(7) it is still wrong
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";
}
}