Increment a Number with JavaScript by Daniel

I am trying to change the code ++ to get the value of 88 but I’m lost. Please help me.

Your code so far

var myVar = 87;

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

**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36</code>.

**Link to the challenge:**

How did you try to use the ++ arithmetic operator?
Did you read the material suggested by the instructions (and looked at the examples?

Yes I did but still no results…

Also in the instructions says that:

is the equivalent of
i = i + 1;

Try to do the same with the exercise.
In the example i is the variable that is increased. In the exercise the variable is myVar.

See what I did. Yet no result.

var myVar = 87;

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

By doing that you are incrementing myVar twice, becoming 89. To pass this exercise only use the line with myVar++.

1 Like

I’m sorry but I don’t understand your explanation.

The initial value of myVar is 87:
var myVar = 87;

Then , these two lines of code, are interpreted/executed one after the other

myVar = myVar + 1;


The first one makes myVar to be 88, and the next 89.

The instructions asks for only adding one to myVar, and to use the ++ arithmetic operator, so you only need to use myVar++;

1 Like

The question says:

Change the code to use the ++ operator on myVar.

Learn more about Arithmetic operators - Increment (++).

That is what I am trying to say in other words.
Also, the expected result for myVar is to be 88:
If you look at the test messages below the green buttons:

myVar should equal 88

You almost write the right code, the only problem is that you left the myVar = myVar + 1; unchanged. You need to replace that line with the code that uses the equivalent myVar++;

Thanks so much. It’s Done.