(Increment) a Number with JavaScript

This is my code so far.What i could wrong??

Your code so far

var myVar = 87;

// Only change code below this line
myVar = myVar; //runs as myVar = 88
myVar = myVar++; //runs as myVar = 87
myVar = myVar+1; //runs as myVar = 88```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36```.

**Link to the challenge:**
https://www.freecodecamp.org/challenges/increment-a-number-with-javascript

No increment here I think.

You only need to modify the original line of:

myVar = myVar + 1;

Do not add any additional lines of code.

If you look at the example in the challenge instructions, you will see how i++; replaced i = i + 1;

You need to apply the same principle to your code. myVar is a variable just like i is in the example.

I don’t understand can you explain me more σιμπλε

What do you not understand?

can you tell me more simple that all

You still have to tell me exactly what you do not understand? I do not know if you do not understand what the instructions are asking you to do or if you do not understand what the ++ operator does. We can not help you unless you explain what you want help with.

myVar++; // this is the same as...
myVar = myVar+1; //this

both lines will add 1 to the number.

1 Like

I don’t understand where to put the myVar=myVar

Delete it. It is useless.

Looking at the problem you’re just supposed to change the code to use ++, this is a little tricky if you don’t know how the return works. myVar++; will increment myVar, but return the old value of myVar.
So myVar = myVar++; does not actually change the value. ++myVar will increment and return the new value so myVar = ++myVar; would work, but it’s unnecessary. the whole myVar = myVar + 1; can be replaced with simply myVar++; by itself.

2 Likes

thank for your help but i did it

1 Like

[quote=“Logiar, post:11, topic:180754”]
Thank you for 1. Being NICE 2. Being Specific and helpful