Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator.md
2023-04-06 18:55:43 +02:00

2.8 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244d8 Порівняння з логічним оператором and 1 https://scrimba.com/c/cvbRVtr 16799 comparisons-with-the-logical-and-operator

--description--

Іноді потрібно перевірити декілька речей одночасно. Логічний оператор and (&&) повертає true лише за умови, що операнди зліва та справа істинні.

The same effect could be achieved by nesting an if statement inside another if.

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

This code will return Yes if num is greater than 5 and less than 10. The same logic can be written with the logical and operator.

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

--instructions--

Замініть дві інструкції if на одну інструкцію, використавши оператор &&, який поверне рядок Yes, якщо val менше чи дорівнює 50 та більше чи дорівнює 25. В іншому випадку поверніть рядок No.

--hints--

Ви повинні використати оператор && лише раз

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

Ви повинні мати лише одну інструкцію if

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