Increment a Number with JavaScript - need help

Increment a Number with JavaScript - need help
0

#1

Tell us what’s happening:

Your code so far


var myVar = 87;

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

Your browser information:

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

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


#2

You have several issues.

You were supposed to only change the one line. Instead, you left the line in your code (unchanged) and added other code.

The final value of myVar should be 88. Let’s look at what your code does.

var myVar = 87; // myVar starts off as 87
myVar = myVar + 1; // myVar is now 88 after adding 1 to it and reassigning the result back to myVar
myVar = myVar; // this just assigns the value 88 back to myVar so nothing changes
myVar++; // this line increments myVar by 1, so the final value of myVar is 89.

#3

Wow, thanks for the quick answer.
As usual, making this much harder on myself.