--Increment a Number with JavaScript

--Increment a Number with JavaScript
0

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

If you need help with a different challenge, use the Ask for help button on the challenge and explain what help you need.

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

???

Like I said before, you appear to be asking about a different challenge than the original poster of this topic. Please create a new topic by clicking the Ask for Help button on the challenge you are working on.

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;