3.1 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 (condition is true) {
statement is executed
}
Наприклад:
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.
Коли test отримує значення true, оператор if оцінює myCondition, щоб побачити чи воно є true чи ні. Оскільки це true, функція повертає It was true. Коли ми викликаємо test зі значенням false, myCondition не true, інструкція у круглих дужках не виконується та функція повертає It was false.
--instructions--
Створіть оператора if всередині функції, щоб повернути Yes, that was true, якщо параметр wasThatTrue є true та повернути No, that was false у протилежному випадку.
--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";
}