2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 56533eb9ac21ba0edf2244a9
|
|
|
|
title: Initializing Variables with the Assignment Operator
|
|
|
|
challengeType: 1
|
2020-05-21 17:31:25 +02:00
|
|
|
isHidden: false
|
2019-02-14 12:24:02 -05:00
|
|
|
videoUrl: 'https://scrimba.com/c/cWJ4Bfb'
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 301171
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
|
|
|
It is common to <dfn>initialize</dfn> a variable to an initial value in the same line as it is declared.
|
|
|
|
<code>var myVar = 0;</code>
|
|
|
|
Creates a new variable called <code>myVar</code> and assigns it an initial value of <code>0</code>.
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
Define a variable <code>a</code> with <code>var</code> and initialize it to a value of <code>9</code>.
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
2018-10-04 14:37:37 +01:00
|
|
|
tests:
|
2019-11-27 02:57:38 -08:00
|
|
|
- text: You should initialize <code>a</code> to a value of <code>9</code>.
|
2019-07-13 00:07:53 -07:00
|
|
|
testString: assert(/var\s+a\s*=\s*9\s*/.test(code));
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
### After Test
|
|
|
|
<div id='js-teardown'>
|
|
|
|
|
|
|
|
```js
|
2018-10-20 21:02:47 +03:00
|
|
|
if(typeof a !== 'undefined') {(function(a){return "a = " + a;})(a);} else { (function() {return 'a is undefined';})(); }
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
var a = 9;
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|