<beginner> Increment a Number with JavaScript

Tell us what’s happening:
Hi everyone, I am really stuck here with this challenge. It keeps saying
myVar = myVar + 1; should be changed
which I don’t even know where I can change it.
:disappointed_relieved:

Your code so far


var myVar = 87;

// Only change code below this line
myVar=++myVar;

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript

You can easily increment or add one to a variable with the ++ operator.

i++;

is the equivalent of

i = i + 1;

Note
The entire line becomes i++;, eliminating the need for the equal sign.

The answer is in the last line

Hi thank you for replying, then I tried this and it is still does not allow me to pass:

var myVar = 87;

// Only change code below this line
++myVar;
1 Like

Yes, and now you’ve stumbled upon pre-increment and post-increment.

Pre-increment means increase the value, and give me the result. So

const i = 0

++i // this will increase 0 to 1, and give you 1

Post-increment means give me the original value, and then increase it. So

const i = 0

i++ // this will give you 0, and then increase to 1
1 Like

Hey! I got it! Thank you so much!:tada:

Please, help me with this too

var myVar = 87;

// Only change code below this line

myVar = ++myVar

what I did wrong?