Files
2022-01-20 20:30:18 +01:00

2.8 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d8 論理積演算子による比較 1 https://scrimba.com/c/cvbRVtr 16799 comparisons-with-the-logical-and-operator

--description--

一度に複数の条件をテストしなければならない場合があります。 論理積演算子 (&&) は、左側と右側のオペランドの両方が true である場合にのみ true を返します。

if ステートメントを別の if ステートメントにネストしても、同じ効果が得られます。

if (num > 5) {
  if (num < 10) {
    return "Yes";
  }
}
return "No";

上の例は、num5 より大きく 10 より小さい場合にのみ Yes を返します。 同じロジックを次のように記述することができます。

if (num > 5 && num < 10) {
  return "Yes";
}
return "No";

--instructions--

&& 演算子を使用して、2つの if ステートメントを 1 つのステートメントにしてください。このプログラムは val25 以上 50 以下の場合に文字列 Yes を返します。 それ以外の場合は文字列 No を返します。

--hints--

&& 演算子を 1 回使用してください。

assert(code.match(/&&/g).length === 1);

if ステートメントを 1 つだけにする必要があります。

assert(code.match(/if/g).length === 1);

testLogicalAnd(0) は文字列 No を返す必要があります。

assert(testLogicalAnd(0) === 'No');

testLogicalAnd(24) は文字列 No を返す必要があります。

assert(testLogicalAnd(24) === 'No');

testLogicalAnd(25) は文字列 Yes を返す必要があります。

assert(testLogicalAnd(25) === 'Yes');

testLogicalAnd(30) は文字列 Yes を返す必要があります。

assert(testLogicalAnd(30) === 'Yes');

testLogicalAnd(50) は文字列 Yes を返す必要があります。

assert(testLogicalAnd(50) === 'Yes');

testLogicalAnd(51) は文字列 No を返す必要があります。

assert(testLogicalAnd(51) === 'No');

testLogicalAnd(75) は文字列 No を返す必要があります。

assert(testLogicalAnd(75) === 'No');

testLogicalAnd(80) は文字列 No を返す必要があります。

assert(testLogicalAnd(80) === 'No');

--seed--

--seed-contents--

function testLogicalAnd(val) {
  // Only change code below this line

  if (val) {
    if (val) {
      return "Yes";
    }
  }

  // Only change code above this line
  return "No";
}

testLogicalAnd(10);

--solutions--

function testLogicalAnd(val) {
  if (val >= 25 && val <= 50) {
    return "Yes";
  }
  return "No";
}