--Increment a Number with JavaScript

Tell us what’s happening:

Your code so far


var myVar = 87;

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

Your browser information:

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

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

2 Likes

Remove this line : myVar = myVar + 1; :smiley:

Here is it: :


var myVar = 87;

// Only change code below this line
 myVar++;
2 Likes

Thank you so much, it worked now. I am newbie here…

2 Likes

var ourDecimal = 5.7;

// Only change code below this line

Please help

Thank you.
Can you help me with that question, i need to create a variable myDecimal and give it a decimal value with a fractional part

var ourDecimal = 5.7;

// Only change code below this line

???

oh, I got it, thank you, i will do it now

Why does myVar++; work and not var myVar = myVar ++1; or etc.?

Because myVar++ is correct syntax, the others are wrong syntax.
Other correct syntaxes of incrementing a variable by one unit are:

myVar += 1;
myVar = myVar + 1;