3.1 KiB
3.1 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244d7 | Comparison with the Less Than Or Equal To Operator | 1 | https://scrimba.com/c/cNVR7Am | 16788 | Сравнение с меньшим или равным оператору |
Description
<=
) (less than or equal to
) сравнивает значения двух чисел. Если число слева меньше или равно числу справа, выражение возвращает true
, и если число слева больше числа справа, оно возвращает false
. Так же как и оператор равенства, less than or equal to
преобразует типы данных. Примеры 4 <= 5 // true
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
Instructions
<=
) чтобы функция работала правильно.
Tests
tests:
- text: <code>testLessOrEqual(0)</code> should return "Smaller Than or Equal to 12"
testString: assert(testLessOrEqual(0) === "Smaller Than or Equal to 12");
- text: <code>testLessOrEqual(11)</code> should return "Smaller Than or Equal to 12"
testString: assert(testLessOrEqual(11) === "Smaller Than or Equal to 12");
- text: <code>testLessOrEqual(12)</code> should return "Smaller Than or Equal to 12"
testString: assert(testLessOrEqual(12) === "Smaller Than or Equal to 12");
- text: <code>testLessOrEqual(23)</code> should return "Smaller Than or Equal to 24"
testString: assert(testLessOrEqual(23) === "Smaller Than or Equal to 24");
- text: <code>testLessOrEqual(24)</code> should return "Smaller Than or Equal to 24"
testString: assert(testLessOrEqual(24) === "Smaller Than or Equal to 24");
- text: <code>testLessOrEqual(25)</code> should return "More Than 24"
testString: assert(testLessOrEqual(25) === "More Than 24");
- text: <code>testLessOrEqual(55)</code> should return "More Than 24"
testString: assert(testLessOrEqual(55) === "More Than 24");
- text: You should use the <code><=</code> operator at least twice
testString: assert(code.match(/val\s*<=\s*('|")*\d+('|")*/g).length > 1);
Challenge Seed
function testLessOrEqual(val) {
if (val) { // Change this line
return "Smaller Than or Equal to 12";
}
if (val) { // Change this line
return "Smaller Than or Equal to 24";
}
return "More Than 24";
}
// Change this value to test
testLessOrEqual(10);
Solution
function testLessOrEqual(val) {
if (val <= 12) { // Change this line
return "Smaller Than or Equal to 12";
}
if (val <= 24) { // Change this line
return "Smaller Than or Equal to 24";
}
return "More Than 24";
}