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