61 lines
2.8 KiB
Markdown
61 lines
2.8 KiB
Markdown
|
---
|
||
|
id: 587d7b88367417b2b2512b46
|
||
|
title: Set Default Parameters for Your Functions
|
||
|
challengeType: 1
|
||
|
videoUrl: ''
|
||
|
localeTitle: Установка параметров по умолчанию для ваших функций
|
||
|
---
|
||
|
|
||
|
## Description
|
||
|
<section id="description"> Чтобы помочь нам создать более гибкие функции, ES6 вводит <dfn>параметры</dfn> по <dfn>умолчанию</dfn> для функций. Проверьте этот код: <blockquote> приветствие функции (name = "Anonymous") { <br> return "Hello" + name; <br> } <br> console.log (приветствие ( "Джон")); // Привет Джон <br> console.log (приветствие ()); // Привет Аноним </blockquote> Параметр по умолчанию запускается, когда аргумент не указан (он не определен). Как вы можете видеть в приведенном выше примере, <code>name</code> параметра получит значение по умолчанию <code>"Anonymous"</code> если вы не указали значение параметра. Вы можете добавить значения по умолчанию для столько параметров, сколько хотите. </section>
|
||
|
|
||
|
## Instructions
|
||
|
<section id="instructions"> Измените <code>increment</code> функции, добавив параметры по умолчанию, чтобы добавить 1 к <code>number</code> если <code>value</code> не указано. </section>
|
||
|
|
||
|
## Tests
|
||
|
<section id='tests'>
|
||
|
|
||
|
```yml
|
||
|
tests:
|
||
|
- text: 'Результат <code>increment(5, 2)</code> должен быть равен <code>7</code> .'
|
||
|
testString: 'assert(increment(5, 2) === 7, "The result of <code>increment(5, 2)</code> should be <code>7</code>.");'
|
||
|
- text: Результатом <code>increment(5)</code> должно быть <code>6</code> .
|
||
|
testString: 'assert(increment(5) === 6, "The result of <code>increment(5)</code> should be <code>6</code>.");'
|
||
|
- text: Параметр по умолчанию <code>1</code> был использован для <code>value</code> .
|
||
|
testString: 'getUserInput => assert(getUserInput("index").match(/value\s*=\s*1/g), "default parameter <code>1</code> was used for <code>value</code>.");'
|
||
|
|
||
|
```
|
||
|
|
||
|
</section>
|
||
|
|
||
|
## Challenge Seed
|
||
|
<section id='challengeSeed'>
|
||
|
|
||
|
<div id='js-seed'>
|
||
|
|
||
|
```js
|
||
|
const increment = (function() {
|
||
|
"use strict";
|
||
|
return function increment(number, value) {
|
||
|
return number + value;
|
||
|
};
|
||
|
})();
|
||
|
console.log(increment(5, 2)); // returns 7
|
||
|
console.log(increment(5)); // returns 6
|
||
|
|
||
|
```
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</section>
|
||
|
|
||
|
## Solution
|
||
|
<section id='solution'>
|
||
|
|
||
|
```js
|
||
|
// solution required
|
||
|
```
|
||
|
</section>
|