Basic JavaScript - Compound Assignment With Augmented Addition

Tell us what’s happening:
I DONT EVEN KNOW WHAT TO SAY…well i dont know what i have to do…? where do i put += ? java script is confusing for me i hope i grasp the concept soon In Sha Allah! Please somebody help may Allah guide you all. Aaam

Your code so far

let a = 3;
let b = 17;
let c = 12;

// Only change code below this line
a = a + 12;
b = 9 + b;
c = c + 7;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Compound Assignment With Augmented Addition

Link to the challenge:

In JS (and a lot of languages),

x = x + 2;

can be written as

x += 2;

So, if you have

a = a + 12;

how would you change that?

That may raise the question - Why have two ways to do the same thing?

Well, it’s a holdover from assembler, writing in machine code. There was a separate operation to add a number to an existing variable that was faster and used less memory and fewer commands. In a modern languages, that isa convenience. If the number you are adding is 1, there is a third way:

x = x + 1;
x += 1;
x++;
++x;

Those all do the same thing. In a modern language, I don’t know that there is any great advantage other than it is subjectively cleaner. It looks odd at first, but you get used to it.

1 Like

you have to remove the variables(a,b,c) and the + after the equal sign and change the the equal sign with +=

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.