Increment a Number with JavaScript idk what's going on

What’s the problem

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_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

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

Hi ! you do not need to use equal sign when your are using ++ operator.

Below is the solution:

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

There is no problem. This is just showing you a shorthand syntax.

i = i+1;

Can be written as

i++;

Don’t read too much into it. They are just showing you another way to add 1 to a variable. It is very common to use this shorthand so it is important to know what it is, however there is no logic problem here. It is just syntax.

if you’re incrementing your variable by 1, like in the challenge
myVar = myVar + 1;
you can use a shorthand syntax: myVar++
what you’ve written is myVar = myVar++ which evaluate as myVar=myVar=myVar+1 which doesn’t make sense.
Solution for your problem is, replace your code myVar = myVar++; with myVar++; :slight_smile:

Also, see the difference between ++myVar and myVar++ :slight_smile: