1.8 KiB
1.8 KiB
id, challengeType, videoUrl, forumTopicId, title
id | challengeType | videoUrl | forumTopicId | title |
---|---|---|---|---|
56533eb9ac21ba0edf2244af | 1 | https://scrimba.com/c/cDR6LCb | 16661 | 复合赋值之 += |
Description
=
右边的内容,所以我们可以写这样的语句:
myVar = myVar + 5;
以上是最常见的运算赋值语句,即先运算、再赋值。还有一类操作符是一步到位既做运算也赋值的。
其中一种就是+=
运算符。
var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6
Instructions
+=
操作符实现同样的效果。
Tests
tests:
- text: <code>a</code>应该等于<code>15</code>。
testString: assert(a === 15);
- text: <code>b</code>应该等于<code>26</code>。
testString: assert(b === 26);
- text: <code>c</code>应该等于<code>19</code>。
testString: assert(c === 19);
- text: 你应该对每个变量使用<code>+=</code>操作符。
testString: assert(code.match(/\+=/g).length === 3);
- text: 不要修改注释上面的代码。
testString: assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code));
Challenge Seed
var a = 3;
var b = 17;
var c = 12;
// Only modify code below this line
a = a + 12;
b = 9 + b;
c = c + 7;
After Test
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
Solution
var a = 3;
var b = 17;
var c = 12;
a += 12;
b += 9;
c += 7;