# freeCodeCamp Challenge Guide: Returning Boolean Values from Functions

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 7, 2016, 9:14pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273 "2016-07-07T21:14:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 7, 2016, 9:14pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/1 "2016-07-07T21:14:26Z")

</div>

# [Returning Boolean Values from Functions](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/returning-boolean-values-from-functions)

* * *

## Problem Explanation

Instead of using an if/else block to compare variable we can do it right inside the return statement with a comparison operator and minmal code.

_Fix the function `isLess` to remove the `if...else` statements._

```js
// Fix this code
if (a < b) {
  return true;
} else {
  return false;
}

```

* * *

## Hints

### Hint 1

As with the [previous exercise](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/replacing-if-else-chains-with-switch) you are about to change how the function returns the correct value, meaning you don’t have to reuse or modify that code but to substitute it.

### Hint 2

In order to return `true` or `false` you don’t need two statements nor use `if` ones. The correct [comparison operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators) is all you need.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> ```javascript
> function isLess(a, b) {
> // Fix this code
> return a <= b;
> }
> // Change these values to test
> isLess(10, 15);
> 
> ```
> 
> #### Relevant Links
> 
> - [“Less than or equal operator (\<=)” - _MDN JavaScript Reference_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Less_than_or_equal_operator_(%3C))

---

<div class="post-metadata">

**Author:** ![BlendSalihu](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@BlendSalihu](https://forum.freecodecamp.org/u/BlendSalihu)\
**Post date:** [July 3, 2017, 10:59pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/2 "2017-07-03T22:59:50Z")

</div>

I really don’t understand this one! can someone help?

---

<div class="post-metadata">

**Author:** ![Marry-ju-Anna](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Marry-ju-Anna](https://forum.freecodecamp.org/u/Marry-ju-Anna)\
**Post date:** [July 4, 2017, 11:58am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/3 "2017-07-04T11:58:56Z")

</div>

Watch what you have in Instructions. - create function less then  
function isLess(a, b) {  
// Fix this code  
return a \< b;

}  
this would work

---

<div class="post-metadata">

**Author:** ![KBPsystem777](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kbpsystem777/32/61555_2.png) [@KBPsystem777](https://forum.freecodecamp.org/u/KBPsystem777)\
**Post date:** [July 25, 2017, 12:05pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/4 "2017-07-25T12:05:19Z")

</div>

## Further explanation:

The purpose of **`isLess()`** is to determine whether **a** value is less than **b** value.  
So if a is less than b, the answer should be TRUE. If not, you should receive a FALSE response in the console.

---

<div class="post-metadata">

**Author:** ![ChristopherMcIntosh](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/christophermcintosh/32/161602_2.png) [@ChristopherMcIntosh](https://forum.freecodecamp.org/u/ChristopherMcIntosh)\
**Post date:** [July 25, 2017, 7:36pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/5 "2017-07-25T19:36:57Z")

</div>

This worked for me.

function isLess(a, b) {  
switch (true) {  
case a \< b:  
answer = true;  
break;  
case a \> b:  
answer = false;  
break;  
}  
return answer;  
}

---

<div class="post-metadata">

**Author:** ![leader285431](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@leader285431](https://forum.freecodecamp.org/u/leader285431)\
**Post date:** [July 28, 2017, 6:55am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/6 "2017-07-28T06:55:09Z")

</div>

it works for me.

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

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

```

---

<div class="post-metadata">

**Author:** ![olaprogramy](https://avatars.discourse-cdn.com/v4/letter/o/dc4da7/32.png) [@olaprogramy](https://forum.freecodecamp.org/u/olaprogramy)\
**Post date:** [July 28, 2017, 8:10pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/7 "2017-07-28T20:10:19Z")

</div>

why so long, just:

function isLess(a,b) {  
return a \< b;  
}

working fine

---

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 10, 2019, 1:21am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/9 "2019-08-10T01:21:16Z")

</div>

Opened on August 10, 2019, 1:21am UTC



---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2025, 12:00pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-returning-boolean-values-from-functions/18273/10 "2025-01-07T12:00:20Z")

</div>

Closed on January 7, 2025, 12:00pm UTC


