2.6 KiB
2.6 KiB
id | title | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244d6 | Comparison with the Less Than Operator | 1 | https://scrimba.com/c/cNVRWtB | 16789 | Сравнение с Менеджером оператора |
Description
<
) сравнивает значения двух чисел. Если число слева меньше числа справа, оно возвращает true
. В противном случае возвращается false
. Как и оператор равенства, меньше, чем оператор, преобразует типы данных при сравнении. Примеры 2 <5 // true
'3' <7 // true
5 <5 // false
3 <2 // false
'8' <4 // false
Instructions
less than
операторов к указанным линиям так, чтобы операторы return имели смысл.
Tests
tests:
- text: <code>testLessThan(0)</code> should return "Under 25"
testString: assert(testLessThan(0) === "Under 25");
- text: <code>testLessThan(24)</code> should return "Under 25"
testString: assert(testLessThan(24) === "Under 25");
- text: <code>testLessThan(25)</code> should return "Under 55"
testString: assert(testLessThan(25) === "Under 55");
- text: <code>testLessThan(54)</code> should return "Under 55"
testString: assert(testLessThan(54) === "Under 55");
- text: <code>testLessThan(55)</code> should return "55 or Over"
testString: assert(testLessThan(55) === "55 or Over");
- text: <code>testLessThan(99)</code> should return "55 or Over"
testString: assert(testLessThan(99) === "55 or Over");
- 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 testLessThan(val) {
if (val) { // Change this line
return "Under 25";
}
if (val) { // Change this line
return "Under 55";
}
return "55 or Over";
}
// Change this value to test
testLessThan(10);
Solution
function testLessThan(val) {
if (val < 25) { // Change this line
return "Under 25";
}
if (val < 55) { // Change this line
return "Under 55";
}
return "55 or Over";
}