--- id: 56533eb9ac21ba0edf2244d8 title: Comparisons with the Logical And Operator challengeType: 1 videoUrl: https://scrimba.com/c/cvbRVtr forumTopicId: 16799 localeTitle: Сравнение с логикой и оператором --- ## Description
Иногда вам нужно проверять несколько штук одновременно. Логический и operator ( && ) возвращают true тогда и только тогда, когда операнды слева и справа от него являются истинными. Тот же эффект может быть достигнут путем вложения выражения if внутри другого, если:
если (num> 5) {
если (num <10) {
вернуть «Да»;
}
}
вернуть «Нет»;
будет возвращаться только «Да», если num больше 5 и меньше 10 . Та же логика может быть записана как:
if (num> 5 && num <10) {
вернуть «Да»;
}
вернуть «Нет»;
## Instructions
Объедините два оператора if в один оператор, который вернет "Yes" если значение val меньше или равно 50 и больше или равно 25 . В противном случае вернется "No" .
## Tests
```yml tests: - text: You should use the && operator once testString: assert(code.match(/&&/g).length === 1); - text: You should only have one if statement testString: assert(code.match(/if/g).length === 1); - text: testLogicalAnd(0) should return "No" testString: assert(testLogicalAnd(0) === "No"); - text: testLogicalAnd(24) should return "No" testString: assert(testLogicalAnd(24) === "No"); - text: testLogicalAnd(25) should return "Yes" testString: assert(testLogicalAnd(25) === "Yes"); - text: testLogicalAnd(30) should return "Yes" testString: assert(testLogicalAnd(30) === "Yes"); - text: testLogicalAnd(50) should return "Yes" testString: assert(testLogicalAnd(50) === "Yes"); - text: testLogicalAnd(51) should return "No" testString: assert(testLogicalAnd(51) === "No"); - text: testLogicalAnd(75) should return "No" testString: assert(testLogicalAnd(75) === "No"); - text: testLogicalAnd(80) should return "No" testString: assert(testLogicalAnd(80) === "No"); ```
## Challenge Seed
```js function testLogicalAnd(val) { // Only change code below this line if (val) { if (val) { return "Yes"; } } // Only change code above this line return "No"; } // Change this value to test testLogicalAnd(10); ```
## Solution
```js function testLogicalAnd(val) { if (val >= 25 && val <= 50) { return "Yes"; } return "No"; } ```