2.0 KiB
2.0 KiB
id, challengeType, videoUrl, forumTopicId, localeTitle
id | challengeType | videoUrl | forumTopicId | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244a8 | 1 | https://scrimba.com/c/cEanysE | 18310 | 使用赋值运算符存储值 |
Description
myVariable = 5;
这条语句把Number
类型的值5
赋给变量myVariable
。
赋值过程是从右到左进行的。在将值分配给运算符左侧的变量之前,将解析=
运算符右侧的所有内容。
myVar = 5;
myNum = myVar;
数值5
被赋给变量myVar
中,然后再次将变量myVar
解析为5
并将其赋给myNum
变量。
Instructions
7
赋给变量 a
。
把变量a
中的内容赋给变量b
。
Tests
tests:
- text: 不要修改注释上方的代码。
testString: assert(/var a;/.test(code) && /var b = 2;/.test(code));
- text: <code>a</code>的值应该是 7。
testString: assert(typeof a === 'number' && a === 7);
- text: <code>b</code>的值应该是 7。
testString: assert(typeof b === 'number' && b === 7);
- text: 你需要用<code>=</code>把<code>a</code>的值赋给<code>b</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;