Returning Boolean Values from Functions

Returning Boolean Values from Functions
0

#1

see the code below

function isLess(a, b) {
// Fix this code
if (a < b) {
return true;
} else {
return false;
}
}

// Change these values to test
isLess(10, 15);

This how i fixed it

function isLess(a, b) {
// Fix this code
if (a ===b) {
return true;
} else {
return false;
}
}

// Change these values to test
isLess(10, 15);
the question now is i should not use any if or else statements


#3

I know that but the question to fix is nit to use the if statement. i don’t understand what you are trying to explain to me


#5

its the most simple answers that always stump me… i try to make it harder on myself lol


#6

function isLess(a, b) {
// Fix this code
return a < b;

}

// Change these values to test
isLess(10, 15);


#7

thank you so much i was having a very hard time with it too


#8

@robelte Getting the answer from the forums is easy, but do you know why? It’s

return a < b;

#9

Yeah…Killing hours on this…


#10

I put that answer in there and got it right, but I thought I was taking a shortcut by not using ===.

If “return a < b;” is correct I feel the question is misleading. Why go on about comparisons and have a link to the earlier question: “Comparison with the Equality Operator”?

(Edit: Raised a GitHub issue)


#11

I was trying to use the switch function, but switch (a < b) doesn’t work. Indeed this is a much more simple answer, just wish I would have found out by myself!