[SOLVED] Compound Assignment With Augmented Addition (Help needed)

Tell us what’s happening:
I’m so stuck on this, I really don’t know what to do

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;

**Link to the challenge:**

You’re gonna use the compound assignment operator += to add a number to a variable and assign it at the same time.

If you have

a = a + 42;

you can use += as a shorter version:

a += 42;

Thank You so much, do you also know how to do the subtraction bit? I’m confused
var a = 11;
var b = 9;
var c = 3;

// Only modify code below this line

a -= a - 6;
b -= b - 15;
c -= c - 1;
that’s what I have so far

It’s also the same idea/pattern with subtraction (and in general, operations that require two operands).

Is it the same for Multiplication and Division or is it another concept?

Yep. Totally the same :wink:

I’m really confused :frowning:

Can you tell what exactly confuses you?

This is what I came up with, for the multiplication

var a = 5;
var b = 12;
var c = 4.6;

// Only modify code below this line

a *= 25;
b *= 36;
c *= 46;

What am I doing wrong?

Why are you multiplying a by 25 and assigning it back to a? The original code multiplied a by 5 and assigned it back to a.

I’m very confused, I thought what I was doing was making it right

I will just use the code involving variable a and then you can apply the logic to the other variables (b and c).

Original code for variable a is below:

var a = 5;
a = a * 5;

You are just going to replace the 2nd line with code that uses the *= operator. So you will have:

a *= ???;

You just have figure out what ??? needs to be in the above line. Remember, the original code multiplied a by 5 and then assigned it back to a.

Thanks, I got how to do it. I really appreciate your help

The pattern of operating on a variable and assigning it back to that variable is so common that there’s a short-hand way of writing it.

Instead of writing a = a + 3 you can just write a += 3. Same for all the other arithmetic operators. It’s just a different way of writing the same thing, but you only need to refer to the named variable once.

Thanks, I got the hang of it now :smiley: