Challenge: Change the function isLess to remove if/else statements:
Before Change:
function isLess(a, b) {
// Only change code below this line
if (a < b) {
return true;
} else {
return false;
}
// Only change code above this line
}
isLess(10, 15);
My Code:
function isLess(a, b) {
// Only change code below this line
function isLess(a, b)
{return a < b;}
10 < 15;
{return b < a;}
15< 10;
// Only change code above this line
}
isLess(10, 15);
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
@Aimslee I don’t know if that is actually your code or if something went wrong when you posted it. But you have the function declaration twice and you have some extra code inside.
All you need is one line of code (and the function obviously):
@ILM Thank you for your reply! I’ll include the backticks and I’ll be more organized next time. And I see that @lasjorg has included the challenge. Thank you!
I actually tried this code (well, similar to it) and it didn’t work. I kept getting the following comment shown in image below:
So, it eventually evolved into what I posted earlier. Thank you everyone for all your inputs. It is so helpful especially when I’m stuck on ones like these.
Oh, by the way, the latest one I’ve tried is the one below and still didn’t work:
function isLess(a,b) {return a<b;}
I think I’m going to study more into it tomorrow and call it a night for today.
could you post all the code you have in the editor? it seems you have extra stuff that makes the test fails
or you removed stuff
if you added that line inside the comments that it indicates where to edit it fails because you have declared a function that is never called inside an other function that is called