2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244d6
2021-02-06 04:42:36 +00:00
title: Comparison with the Less Than Operator
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cNVRWtB'
forumTopicId: 16789
2021-01-13 03:31:00 +01:00
dashedName: comparison-with-the-less-than-operator
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
The < dfn > less than</ dfn > operator (`<` ) compares the values of two numbers. If the number to the left is less than the number to the right, it returns `true` . Otherwise, it returns `false` . Like the equality operator, < dfn > less than</ dfn > operator converts data types while comparing.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
**Examples**
2020-04-29 18:29:13 +08:00
```js
2 < 5 / / true
'3' < 7 / / true
5 < 5 / / false
3 < 2 / / false
'8' < 4 / / false
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Add the less than operator to the indicated lines so that the return statements make sense.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testLessThan(0)` should return "Under 25"
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(testLessThan(0) === 'Under 25');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testLessThan(24)` should return "Under 25"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testLessThan(24) === 'Under 25');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`testLessThan(25)` should return "Under 55"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testLessThan(25) === 'Under 55');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testLessThan(54)` should return "Under 55"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testLessThan(54) === 'Under 55');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testLessThan(55)` should return "55 or Over"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testLessThan(55) === '55 or Over');
```
2021-02-06 04:42:36 +00:00
`testLessThan(99)` should return "55 or Over"
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(testLessThan(99) === '55 or Over');
```
2020-04-29 18:29:13 +08:00
2021-02-06 04:42:36 +00:00
You should use the `<` operator at least twice
2020-04-29 18:29:13 +08:00
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/val\s*< \s*('|")*\d+('|")*/g).length > 1);
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
function testLessThan(val) {
if (val) { // Change this line
return "Under 25";
}
if (val) { // Change this line
return "Under 55";
}
return "55 or Over";
}
testLessThan(10);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function testLessThan(val) {
if (val < 25 ) { / / Change this line
return "Under 25";
}
if (val < 55 ) { / / Change this line
return "Under 55";
}
return "55 or Over";
}
```