2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244d4
2021-02-06 04:42:36 +00:00
title: Comparison with the Greater 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/cp6GbH4'
forumTopicId: 16786
2021-01-13 03:31:00 +01:00
dashedName: comparison-with-the-greater-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 greater than operator (`>` ) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns `true` . Otherwise, it returns `false` .
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
Like the equality operator, greater than operator will convert data types of values 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
5 > 3 // true
7 > '3' // true
2 > 3 // false
'1' > 9 // 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 greater 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
`testGreaterThan(0)` should return "10 or Under"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(0) === '10 or Under');
```
2021-02-06 04:42:36 +00:00
`testGreaterThan(10)` should return "10 or Under"
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(testGreaterThan(10) === '10 or Under');
```
2021-02-06 04:42:36 +00:00
`testGreaterThan(11)` should return "Over 10"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(11) === 'Over 10');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testGreaterThan(99)` should return "Over 10"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(99) === 'Over 10');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`testGreaterThan(100)` should return "Over 10"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(100) === 'Over 10');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testGreaterThan(101)` should return "Over 100"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(101) === 'Over 100');
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`testGreaterThan(150)` should return "Over 100"
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(testGreaterThan(150) === 'Over 100');
```
2021-02-06 04:42:36 +00:00
You should use the `>` operator at least twice
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(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 testGreaterThan(val) {
if (val) { // Change this line
return "Over 100";
}
if (val) { // Change this line
return "Over 10";
}
return "10 or Under";
}
testGreaterThan(10);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
function testGreaterThan(val) {
if (val > 100) { // Change this line
return "Over 100";
}
if (val > 10) { // Change this line
return "Over 10";
}
return "10 or Under";
}
```