2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244d6
title: Comparison with the Less Than Operator
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cNVRWtB'
2019-07-31 11:32:23 -07:00
forumTopicId: 16789
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
The < dfn > less than< / dfn > operator (< code > < < / code > ) compares the values of two numbers. If the number to the left is less than the number to the right, it returns < code > true< / code > . Otherwise, it returns < code > false< / code > . Like the equality operator, < dfn > less than< / dfn > operator converts data types while comparing.
< strong > Examples< / strong >
2019-05-17 06:20:30 -07:00
```js
2 < 5 / / true
'3' < 7 / / true
5 < 5 / / false
3 < 2 / / false
'8' < 4 / / false
```
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
2019-10-27 15:45:37 -01:00
Add the less than operator to the indicated lines so that the return statements make sense.
2018-09-30 23:01:58 +01:00
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: < code > testLessThan(0)</ code > should return "Under 25"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(0) === "Under 25");
2018-10-04 14:37:37 +01:00
- text: < code > testLessThan(24)</ code > should return "Under 25"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(24) === "Under 25");
2018-10-04 14:37:37 +01:00
- text: < code > testLessThan(25)</ code > should return "Under 55"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(25) === "Under 55");
2018-10-04 14:37:37 +01:00
- text: < code > testLessThan(54)</ code > should return "Under 55"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(54) === "Under 55");
2018-10-04 14:37:37 +01:00
- text: < code > testLessThan(55)</ code > should return "55 or Over"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(55) === "55 or Over");
2018-10-04 14:37:37 +01:00
- text: < code > testLessThan(99)</ code > should return "55 or Over"
2019-07-13 00:07:53 -07:00
testString: assert(testLessThan(99) === "55 or Over");
2018-10-04 14:37:37 +01:00
- text: You should use the < code > < </ code > operator at least twice
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/val\s*< \s*('|")*\d+('|")*/g).length > 1);
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function testLessThan(val) {
if (val) { // Change this line
return "Under 25";
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
if (val) { // Change this line
return "Under 55";
}
return "55 or Over";
}
testLessThan(10);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
function testLessThan(val) {
if (val < 25 ) { / / Change this line
return "Under 25";
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
if (val < 55 ) { / / Change this line
return "Under 55";
}
return "55 or Over";
}
```
< / section >