From 64d7eba61baafc258858584d8f2be624ec8af71b Mon Sep 17 00:00:00 2001 From: Adrian Skar Date: Fri, 8 Mar 2019 23:42:05 +0100 Subject: [PATCH] [Guide] Basic JS: Greater than operator. Enhancements (#28510) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Guide] Basic JS: Greater than operator. Enhancements From [this PR on the old guide repo](https://github.com/freeCodeCamp/guide/pull/8663). · Added problem explanation, run code example, code explanation and resources. * fix: removed repl.it link --- .../index.md | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator/index.md index ab877ffa1a..adc10227ab 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator/index.md @@ -1,20 +1,42 @@ --- -title: Comparison with the Greater Than Operator +title: Comparison with the greater than operator (>) --- -## Comparison with the Greater Than Operator +## Comparison with the Greater Than Operator (>) -`>` (Greater Than) is a logical operator that returns true case the value on the left is higher than the one on the right. -## Basic Solution +### Problem explanation: +· _Add the `greater than` operator to the indicated lines so that the return statements make sense._ + +#### Hint 1 +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. +> _try to solve the problem now_ +> + +## Spoiler alert! + +**Solution ahead!** + +## Basic code solution: ```javascript function testGreaterThan(val) { - if (val > 100) + if (val > 100) { // Change this line return "Over 100"; + } - if (val > 10) + if (val > 10) { // Change this line return "Over 10"; + } - return "10 or Under"; + return "10 or under"; } + +// Change this value to test +testGreaterThan(10); ``` +### Code explanation +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". + +### Resources + +- ["Greater than operator (>)" - *MDN JavaScript reference*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Greater_than_operator_(%3E))