freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/initializing-variables-with-the-assignment-operator.english.md
Valeriy 79d9012432 fix(curriculum): quotes in tests (#18828)
* fix(curriculum): tests quotes

* fix(curriculum): fill seed-teardown

* fix(curriculum): fix tests and remove unneeded seed-teardown
2018-10-20 23:32:47 +05:30

1.2 KiB

id, title, challengeType
id title challengeType
56533eb9ac21ba0edf2244a9 Initializing Variables with the Assignment Operator 1

Description

It is common to initialize a variable to an initial value in the same line as it is declared. var myVar = 0; Creates a new variable called myVar and assigns it an initial value of 0.

Instructions

Define a variable a with var and initialize it to a value of 9.

Tests

tests:
  - text: Initialize <code>a</code> to a value of <code>9</code>
    testString: assert(/var\s+a\s*=\s*9\s*/.test(code), 'Initialize <code>a</code> to a value of <code>9</code>');

Challenge Seed

// Example
var ourVar = 19;

// Only change code below this line

After Test

if(typeof a !== 'undefined') {(function(a){return "a = " + a;})(a);} else { (function() {return 'a is undefined';})(); }

Solution

var a = 9;