2.4 KiB
2.4 KiB
id, title, challengeType, forumTopicId, localeTitle
| id | title | challengeType | forumTopicId | localeTitle |
|---|---|---|---|---|
| 587d7b88367417b2b2512b46 | Set Default Parameters for Your Functions | 1 | 301209 | Установка параметров по умолчанию для ваших функций |
Description
приветствие функции (name = "Anonymous") {Параметр по умолчанию запускается, когда аргумент не указан (он не определен). Как вы можете видеть в приведенном выше примере,
return "Hello" + name;
}
console.log (приветствие ( "Джон")); // Привет Джон
console.log (приветствие ()); // Привет Аноним
name параметра получит значение по умолчанию "Anonymous" если вы не указали значение параметра. Вы можете добавить значения по умолчанию для столько параметров, сколько хотите.
Instructions
increment функции, добавив параметры по умолчанию, чтобы добавить 1 к number если value не указано.
Tests
tests:
- text: The result of <code>increment(5, 2)</code> should be <code>7</code>.
testString: assert(increment(5, 2) === 7);
- text: The result of <code>increment(5)</code> should be <code>6</code>.
testString: assert(increment(5) === 6);
- text: Default parameter <code>1</code> was used for <code>value</code>.
testString: assert(code.match(/value\s*=\s*1/g));
Challenge Seed
const increment = (number, value) => number + value;
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6
Solution
const increment = (number, value = 1) => number + value;