66 lines
2.2 KiB
Markdown
66 lines
2.2 KiB
Markdown
---
|
||
id: 56533eb9ac21ba0edf2244c0
|
||
title: Global vs. Local Scope in Functions
|
||
challengeType: 1
|
||
videoUrl: ''
|
||
localeTitle: Глобальная и локальная область функций
|
||
---
|
||
|
||
## Description
|
||
<section id="description"> Можно иметь как <dfn>локальные, так</dfn> и <dfn>глобальные</dfn> переменные с тем же именем. Когда вы это делаете, <code>local</code> переменная имеет приоритет над <code>global</code> переменной. В этом примере: <blockquote> var someVar = "Hat"; <br> function myFun () { <br> var someVar = "Голова"; <br> return someVar; <br> } </blockquote> Функция <code>myFun</code> вернет <code>"Head"</code> потому что присутствует <code>local</code> версия переменной. </section>
|
||
|
||
## Instructions
|
||
<section id="instructions"> Добавьте локальную переменную в функцию <code>myOutfit</code> чтобы переопределить значение <code>outerWear</code> с помощью <code>"sweater"</code> . </section>
|
||
|
||
## Tests
|
||
<section id='tests'>
|
||
|
||
```yml
|
||
tests:
|
||
- text: Не изменяйте значение глобального <code>outerWear</code>
|
||
testString: 'assert(outerWear === "T-Shirt", "Do not change the value of the global <code>outerWear</code>");'
|
||
- text: <code>myOutfit</code> должен вернуть <code>"sweater"</code>
|
||
testString: 'assert(myOutfit() === "sweater", "<code>myOutfit</code> should return <code>"sweater"</code>");'
|
||
- text: Не меняйте оператор возврата
|
||
testString: 'assert(/return outerWear/.test(code), "Do not change the return statement");'
|
||
|
||
```
|
||
|
||
</section>
|
||
|
||
## Challenge Seed
|
||
<section id='challengeSeed'>
|
||
|
||
<div id='js-seed'>
|
||
|
||
```js
|
||
// Setup
|
||
var outerWear = "T-Shirt";
|
||
|
||
function myOutfit() {
|
||
// Only change code below this line
|
||
|
||
|
||
|
||
// Only change code above this line
|
||
return outerWear;
|
||
}
|
||
|
||
myOutfit();
|
||
|
||
```
|
||
|
||
</div>
|
||
|
||
|
||
|
||
</section>
|
||
|
||
## Solution
|
||
<section id='solution'>
|
||
|
||
```js
|
||
// solution required
|
||
```
|
||
</section>
|