Increment a Number with JavaScript by Daniel

Increment a Number with JavaScript by Daniel
0

#1

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:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/increment-a-number-with-javascript

#2

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


#3

Yes I did but still no results…


#4

Also in the instructions says that:

i++;
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.


#5

See what I did. Yet no result.

var myVar = 87;

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


#6

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


#7

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


#8

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;

myVar++;

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++;


#9

The question says:

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

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


#10

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++;


#11

Thanks so much. It’s Done.