2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244af
2021-02-06 04:42:36 +00:00
title: Compound Assignment With Augmented Addition
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cDR6LCb'
forumTopicId: 16661
2021-01-13 03:31:00 +01:00
dashedName: compound-assignment-with-augmented-addition
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say:
2020-12-16 00:37:30 -07:00
`myVar = myVar + 5;`
2021-02-06 04:42:36 +00:00
to add `5` to `myVar` . Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
One such operator is the `+=` operator.
2020-04-29 18:29:13 +08:00
```js
var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Convert the assignments for `a` , `b` , and `c` to use the `+=` operator.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`a` should equal `15` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(a === 15);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`b` should equal `26` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(b === 26);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
`c` should equal `19` .
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(c === 19);
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
You should use the `+=` operator for each variable.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/\+=/g).length === 3);
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should not modify the code above the specified comment.
2020-04-29 18:29:13 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(
/var a = 3;/.test(code) & &
/var b = 17;/.test(code) & &
/var c = 12;/.test(code)
);
2018-10-10 18:03:03 -04:00
```
2020-04-29 18:29:13 +08:00
2021-01-13 03:31:00 +01:00
# --seed--
## --after-user-code--
```js
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
```
## --seed-contents--
```js
var a = 3;
var b = 17;
var c = 12;
// Only change code below this line
a = a + 12;
b = 9 + b;
c = c + 7;
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
var a = 3;
var b = 17;
var c = 12;
a += 12;
b += 9;
c += 7;
```