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

2.9 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
cf1111c1c12feddfaeb3bdef if ステートメントで条件分岐処理を行う 1 https://scrimba.com/c/cy87mf3 18348 use-conditional-logic-with-if-statements

--description--

if ステートメントはコード内の判定に使用されます。 キーワード if は、丸括弧内で定義された特定の条件に基づいて中括弧内のコードを実行するように JavaScript に指示します。 これらの条件のことを Boolean (ブール) 条件と呼び、true または false のみを使用できます。

条件判定が true となった場合、プログラムは中括弧内のステートメントを実行します。 条件判定が false となった場合は、中括弧内のステートメントは実行されません。

擬似コード

if (条件が true) {
  ステートメントを実行する
}

function test (myCondition) {
  if (myCondition) {
    return "It was true";
  }
  return "It was false";
}

test(true);
test(false);

test(true) は文字列 It was true を返し、test(false) は文字列 It was false を返します。

testtrue の値で呼び出された場合、if ステートメントは myCondition を評価し、条件が true かどうかを判定します。 条件が true なので、関数は It was true を返します。 testfalse の値で呼び出された場合、myConditiontrue ではなく、波括弧内の文は実行されません。そして、関数は It was false を返します。

--instructions--

パラメーター wasThatTruetrue の場合は Yes, that was true を、そうでない場合は No, that was false を返すように、関数内に if ステートメントを作成してください。

--hints--

trueOrFalse は関数である必要があります。

assert(typeof trueOrFalse === 'function');

trueOrFalse(true) は文字列を返す必要があります。

assert(typeof trueOrFalse(true) === 'string');

trueOrFalse(false) は文字列を返す必要があります。

assert(typeof trueOrFalse(false) === 'string');

trueOrFalse(true) は文字列 Yes, that was true を返す必要があります。

assert(trueOrFalse(true) === 'Yes, that was true');

trueOrFalse(false) は文字列 No, that was false を返す必要があります。

assert(trueOrFalse(false) === 'No, that was false');

--seed--

--seed-contents--

function trueOrFalse(wasThatTrue) {
  // Only change code below this line



  // Only change code above this line

}

--solutions--

function trueOrFalse(wasThatTrue) {
  if (wasThatTrue) {
    return "Yes, that was true";
  }
  return "No, that was false";
}