Files
freeCodeCamp/curriculum/challenges/japanese/02-javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-or-equal-to-operator.md
2022-02-25 03:41:18 +09:00

2.3 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d5 大なりイコール演算子による比較 1 https://scrimba.com/c/c6KBqtV 16785 comparison-with-the-greater-than-or-equal-to-operator

--description--

大なりイコール演算子 (>=) は、2 つの数値の値を比較します。 左の数値が右の数値よりも大きいか等しい場合は、true を返します。 それ以外の場合は、false を返します。

等価演算子と同様に、大なりイコール演算子でも比較時にデータ型が変換されます。

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.

--hints--

testGreaterOrEqual(0) should return the string Less than 10

assert(testGreaterOrEqual(0) === 'Less than 10');

testGreaterOrEqual(9) should return the string Less than 10

assert(testGreaterOrEqual(9) === 'Less than 10');

testGreaterOrEqual(10) should return the string 10 or Over

assert(testGreaterOrEqual(10) === '10 or Over');

testGreaterOrEqual(11) should return the string 10 or Over

assert(testGreaterOrEqual(11) === '10 or Over');

testGreaterOrEqual(19) should return the string 10 or Over

assert(testGreaterOrEqual(19) === '10 or Over');

testGreaterOrEqual(100) should return the string 20 or Over

assert(testGreaterOrEqual(100) === '20 or Over');

testGreaterOrEqual(21) should return the string 20 or Over

assert(testGreaterOrEqual(21) === '20 or Over');

You should use the >= operator at least twice

assert(code.match(/val\s*>=\s*('|")*\d+('|")*/g).length > 1);

--seed--

--seed-contents--

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";
}

testGreaterOrEqual(10);

--solutions--

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";
}