Returning Boolean to Functions

I’m having trouble figuring out what I did wrong…

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);

Can you please put ``` these symbols on the line before and after your code so that it is more readable?

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.

Note: Backticks are not single quotes.

markdown_Forums

@JeremyLT done

please include the challenge link or explain in more detail what you should do

After the first line, your function should return a value… What are the extra lines for?

Since the expression a<b is true or false your function can just return that without if/else.

function isLess(a,b) return a<b

@ninjasun It would be better if you tried to help the OP without posting the solution. I blurred it just for good measure.

This is the challenge.

@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):

return value1 relationalOperator value2;

@ilenia 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! :slight_smile:

I actually tried this code (well, similar to it) and it didn’t work. I kept getting the following comment shown in image below:

image

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

function isLess(a, b) {
  // Only change code below this line
  function isLess(a,b) {return a<b;}
  // Only change code above this line
}

isLess(10, 15);

Thanks!

Why do you have a function inside of your function? You have the correct comparison but the function inside the function is bizarre.

Because… I can’t read :grimacing: haha I got it now. Thank you!!

1 Like