freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.english.md
Randell Dawson e9212c61d2 fix(curriculum): Remove unnecessary assert message argument from English challenges JavaScript Algorithms and Data Structures - 01 (#36401)
* fix: rm assert msg basic-javascript

* fix: removed more assert msg args

* fix: fixed verbiage

Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com>
2019-07-13 08:07:53 +01:00

2.6 KiB

id, title, challengeType, videoUrl
id title challengeType videoUrl
56533eb9ac21ba0edf2244d5 Comparison with the Greater Than Or Equal To Operator 1 https://scrimba.com/c/c6KBqtV

Description

The greater than or equal to operator (>=) compares the values of two numbers. If the number to the left is greater than or equal to the number to the right, it returns true. Otherwise, it returns false. Like the equality operator, greater than or equal to operator will convert data types while comparing. Examples
6   >=  6   // true
7   >= '3'  // true
2   >=  3   // false
'7' >=  9   // false

Instructions

Add the greater than or equal to operator to the indicated lines so that the return statements make sense.

Tests

tests:
  - text: <code>testGreaterOrEqual(0)</code> should return "Less than 10"
    testString: assert(testGreaterOrEqual(0) === "Less than 10");
  - text: <code>testGreaterOrEqual(9)</code> should return "Less than 10"
    testString: assert(testGreaterOrEqual(9) === "Less than 10");
  - text: <code>testGreaterOrEqual(10)</code> should return "10 or Over"
    testString: assert(testGreaterOrEqual(10) === "10 or Over");
  - text: <code>testGreaterOrEqual(11)</code> should return "10 or Over"
    testString: assert(testGreaterOrEqual(11) === "10 or Over");
  - text: <code>testGreaterOrEqual(19)</code> should return "10 or Over"
    testString: assert(testGreaterOrEqual(19) === "10 or Over");
  - text: <code>testGreaterOrEqual(100)</code> should return "20 or Over"
    testString: assert(testGreaterOrEqual(100) === "20 or Over");
  - text: <code>testGreaterOrEqual(21)</code> should return "20 or Over"
    testString: assert(testGreaterOrEqual(21) === "20 or Over");
  - text: You should use the <code>&gt;=</code> operator at least twice
    testString: assert(code.match(/val\s*>=\s*('|")*\d+('|")*/g).length > 1);

Challenge Seed

function testGreaterOrEqual(val) {
  if (val) {  // Change this line
    return "20 or Over";
  }

  if (val) {  // Change this line
    return "10 or Over";
  }

  return "Less than 10";
}

// Change this value to test
testGreaterOrEqual(10);

Solution

function testGreaterOrEqual(val) {
  if (val >= 20) {  // Change this line
    return "20 or Over";
  }

  if (val >= 10) {  // Change this line
    return "10 or Over";
  }

  return "Less than 10";
}