2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244af
title: Compound Assignment With Augmented Addition
challengeType: 1
2020-05-21 17:31:25 +02:00
isHidden: false
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cDR6LCb'
2019-07-31 11:32:23 -07:00
forumTopicId: 16661
2018-09-30 23:01:58 +01:00
---
## Description
<section id='description'>
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:
<code>myVar = myVar + 5;</code>
to add <code>5</code> to <code>myVar</code>. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.
One such operator is the <code>+=</code> operator.
2019-05-17 06:20:30 -07:00
```js
var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6
```
2018-09-30 23:01:58 +01:00
</section>
## Instructions
<section id='instructions'>
Convert the assignments for <code>a</code>, <code>b</code>, and <code>c</code> to use the <code>+=</code> operator.
</section>
## Tests
<section id='tests'>
```yml
2018-10-04 14:37:37 +01:00
tests:
2019-11-27 02:57:38 -08:00
- text: <code>a</code> should equal <code>15</code>.
2019-07-13 00:07:53 -07:00
testString: assert(a === 15);
2019-11-27 02:57:38 -08:00
- text: <code>b</code> should equal <code>26</code>.
2019-07-13 00:07:53 -07:00
testString: assert(b === 26);
2019-11-27 02:57:38 -08:00
- text: <code>c</code> should equal <code>19</code>.
2019-07-13 00:07:53 -07:00
testString: assert(c === 19);
2019-11-27 02:57:38 -08:00
- text: You should use the <code>+=</code> operator for each variable.
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/\+=/g).length === 3);
2019-11-27 02:57:38 -08:00
- text: You should not modify the code above the specified comment.
2019-07-13 00:07:53 -07:00
testString: assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code));
2018-09-30 23:01:58 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
var a = 3;
var b = 17;
var c = 12;
2020-03-02 23:18:30 -08:00
// Only change code below this line
2018-09-30 23:01:58 +01:00
a = a + 12;
b = 9 + b;
c = c + 7;
```
</div>
### After Test
<div id='js-teardown'>
```js
2018-10-20 21:02:47 +03:00
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = " + c; })(a,b,c);
2018-09-30 23:01:58 +01:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
var a = 3;
var b = 17;
var c = 12;
a += 12;
b += 9;
c += 7;
```
</section>