Challenge Comparison with the Less Than Or Equal To Operator has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function testLessOrEqual(val) {
if (val <= 12) { // Change this line
return "Smaller Than or Equal to 12";
}
if (val <= 24) { // Change this line
return "Smaller Than or Equal to 24";
}
return "25 or More";
}
// Change this value to test
testLessOrEqual(24.99);
Issue:
when I input testLessOrEqual(24.99); the answer or the code returns "25 or more " as the outcome which is not correct - this code might need some improvement
@1810msr The code is behaving correctly as coded though the intention may be different!
Since you are passing 24.99, the next line shown below will not get satisfied (i.e. 24.99 is not less than 24) so the code will jump to the next line which is "25 or More"
if (val <= 24) { // Change this line
return "Smaller Than or Equal to 24";
}
So change the above condition to 25 and accordingly change the last return.
I think the issue is with the string "25 or More"
. If val <= 24
fails in the if-condition, then val
must be greater than 24. Perhaps "More than 24"
is a more appropriate return value.
Please can we have the challenge instructions adjusted to return "More than 24"
if val
is greater than the integer 24.
This is the code for the challenge. Please follow CONTRIBUTING.md and hit us up in the contributors chat if you have any issues
Good luck and Happy Coding!
I would love to give this a shot!
Write the final return statement as return "24.1 or More";. Your condition is just checking below 24. But your value which is 24.99 doesn't satisfy any of the above condition and just returning the String you wrote. So write return "24.1 or more" which makes more sense
I believe "More Than 24" is a more accurate return value because the values
that make it to that else statement can be as close as possible to 24
without equaling 24 when approaching from the positive side. If I were to
change the return value to "24.1 or more" and I passed the function a value
of 24.05, 24.01, 24.001, the function would return the statement saying
that the number is larger than 24.1, which is false.
this can be so confusing
Most helpful comment
I believe "More Than 24" is a more accurate return value because the values
that make it to that else statement can be as close as possible to 24
without equaling 24 when approaching from the positive side. If I were to
change the return value to "24.1 or more" and I passed the function a value
of 24.05, 24.01, 24.001, the function would return the statement saying
that the number is larger than 24.1, which is false.