2018-10-12 15:37:13 -04:00
---
2019-03-08 23:42:05 +01:00
title: Comparison with the greater than operator (>)
2018-10-12 15:37:13 -04:00
---
2019-07-24 00:59:27 -07:00
# Comparison with the Greater Than Operator (>)
2018-10-12 15:37:13 -04:00
2019-07-24 00:59:27 -07:00
---
## Problem Explanation
2019-03-08 23:42:05 +01:00
· _Add the `greater than` operator to the indicated lines so that the return statements make sense._
2019-07-24 00:59:27 -07:00
---
## Hints
### Hint 1
2019-03-08 23:42:05 +01:00
The greater than operator `(>)` compares both operands using type coercion (converting data types if necessary) and returns `true` if the first one is greater than the second one.
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
function testGreaterThan(val) {
2019-07-24 00:59:27 -07:00
if (val > 100) {
// Change this line
2018-10-12 15:37:13 -04:00
return "Over 100";
2019-03-08 23:42:05 +01:00
}
2019-07-24 00:59:27 -07:00
if (val > 10) {
// Change this line
2018-10-12 15:37:13 -04:00
return "Over 10";
2019-03-08 23:42:05 +01:00
}
2018-10-12 15:37:13 -04:00
2019-03-08 23:42:05 +01:00
return "10 or under";
2018-10-12 15:37:13 -04:00
}
2019-03-08 23:42:05 +01:00
// Change this value to test
testGreaterThan(10);
2018-10-12 15:37:13 -04:00
```
2019-07-24 00:59:27 -07:00
#### Code Explanation
2019-03-08 23:42:05 +01:00
The function first evaluates `if` the condition `(val > 100)` evaluates to `true` converting `val` to a number if necessary. If it does, it returns the statement between the curly braces ("Over 100"). If it doesn't, it checks if the next condition is `true` (returning "Over 10"). Otherwise the function will return "10 or under".
2019-07-24 00:59:27 -07:00
#### Relevant Links
2019-03-08 23:42:05 +01:00
- ["Greater than operator (>)" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator_(%3E ))
2019-07-24 00:59:27 -07:00
< / details >