This includes certificates (where it does nothing), but does not include any translations.
2.0 KiB
2.0 KiB
id, title, challengeType, isHidden, videoUrl, forumTopicId
id | title | challengeType | isHidden | videoUrl | forumTopicId |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244a8 | Storing Values with the Assignment Operator | 1 | false | https://scrimba.com/c/cEanysE | 18310 |
Description
myVariable = 5;
This assigns the Number
value 5
to myVariable
.
Assignment always goes from right to left. Everything to the right of the =
operator is resolved before the value is assigned to the variable to the left of the operator.
myVar = 5;
myNum = myVar;
This assigns 5
to myVar
and then resolves myVar
to 5
again and assigns it to myNum
.
Instructions
7
to variable a
.
Assign the contents of a
to variable b
.
Tests
tests:
- text: You should not change code above the specified comment.
testString: assert(/var a;/.test(code) && /var b = 2;/.test(code));
- text: <code>a</code> should have a value of 7.
testString: assert(typeof a === 'number' && a === 7);
- text: <code>b</code> should have a value of 7.
testString: assert(typeof b === 'number' && b === 7);
- text: <code>a</code> should be assigned to <code>b</code> with <code>=</code>.
testString: assert(/b\s*=\s*a\s*;/g.test(code));
Challenge Seed
// Setup
var a;
var b = 2;
// Only change code below this line
Before Test
if (typeof a != 'undefined') {
a = undefined;
}
if (typeof b != 'undefined') {
b = undefined;
}
After Test
(function(a,b){return "a = " + a + ", b = " + b;})(a,b);
Solution
var a;
var b = 2;
a = 7;
b = a;