dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
82 lines
1.5 KiB
Markdown
82 lines
1.5 KiB
Markdown
---
|
|
id: 5679ceb97cbaa8c51670a16b
|
|
title: Returning Boolean Values from Functions
|
|
challengeType: 1
|
|
forumTopicId: 18273
|
|
dashedName: returning-boolean-values-from-functions
|
|
---
|
|
|
|
# --description--
|
|
|
|
You may recall from <a href="/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-equality-operator" target="_blank" rel="noopener noreferrer nofollow">Comparison with the Equality Operator</a> that all comparison operators return a boolean `true` or `false` value.
|
|
|
|
Sometimes people use an `if/else` statement to do a comparison, like this:
|
|
|
|
```js
|
|
function isEqual(a, b) {
|
|
if (a === b) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
```
|
|
|
|
But there's a better way to do this. Since `===` returns `true` or `false`, we can return the result of the comparison:
|
|
|
|
```js
|
|
function isEqual(a, b) {
|
|
return a === b;
|
|
}
|
|
```
|
|
|
|
# --instructions--
|
|
|
|
Fix the function `isLess` to remove the `if/else` statements.
|
|
|
|
# --hints--
|
|
|
|
`isLess(10, 15)` should return `true`
|
|
|
|
```js
|
|
assert(isLess(10, 15) === true);
|
|
```
|
|
|
|
`isLess(15, 10)` should return `false`
|
|
|
|
```js
|
|
assert(isLess(15, 10) === false);
|
|
```
|
|
|
|
You should not use any `if` or `else` statements
|
|
|
|
```js
|
|
assert(!/if|else/g.test(__helpers.removeJSComments(code)));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
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);
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function isLess(a, b) {
|
|
return a < b;
|
|
}
|
|
```
|