JavaScript: Returning Boolean Values from Functions

Hi everyone please can someone explain me this code

function isLess(a, b) {
  // Fix this code
  return a*3 === b*2;
}

where the 3 and the 2 coming from to let this function to return true?

[quote=“Mountaga, post:1, topic:321090, full:true”]
Hi everyone please can someone explain me this code

function isLess(a, b) {
// Fix this code
return a * 3 === b * 2;
}
where the 3 and the 2 coming from to let this function to return true?

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.

Note: Backticks are not single quotes.

markdown_Forums

This function returns true if the parameter a times 3 is equal to the parameter b times 2. For example, isLess(4, 6) would return true and isLess(5, 7) would return false.

3 and 2 aren’t “coming from” anywhere. They are hardcoded into the function.

You shouldn’t be adding any numbers into your code for this exercise. I believe this exercise is trying to demonstrate the concept of relational operators. Your final answer should be similar to the second code block given on the page.

function isEqual(a,b) {
  return a === b;
}

Look at the code above and what it does, then change the relational operator so it returns true if a is less than b, and false if a is equal or greater than b.

<p> here is the result if I don't add any number 
// running tests

isLess(10,15) should return true

// tests completed
</p>
it is okay when I change the relational operator it work fine 
function isLess(a, b) {

// Fix this code

return b>a;

}

// Change these values to test

isLess(10, 15);

isLess(15, 10);

1 Like

14 posts were split to a new topic: Record Collection: Need help with collectionCopy is not defined error