Tell us what’s happening:
Your code so far
var a = 3;
var b = 17;
var c = 12;
// Only modify code below this line
a = a + 12;
b = 9 + b;
c = c + 7;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/compound-assignment-with-augmented-addition
Can you explain what did you understand from the examples given. I will be able to help you out more.
You simple just do this:
//This is your given code
var a = 3;
var b = 17;
var c = 12;
a = a + 12;
b = 9 + b;
c = c + 7;
If you read the explanation
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.
Which means you simply grab your ‘a, b, c’ from the example and do this:
a += 12;
b += 9;
c += 7;
And this is the same thing.
1 Like
So in the example
myVar = myVar + 5;
becomes:
myVar += 5;
when we have:
b = 9 + b;
it’s the same
b + = 9;
we can even make our own
x = 11 + x:
x +=11;