Increment a Number with JavaScript help plss

Increment a Number with JavaScript help plss
0

#1

Tell us what’s happening:

Your code so far


var myVar = 87;

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

Your browser information:

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

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


#2

Hi :sunny:.

myVar = 0;

Increment a number with ++.
Decrement a number with --.
But :

myVar = myVar + 1;
// Output 1.

is not equal to :

myVar = myVar++;
// Output 0.

Because the ++ is checked after the assignment.
You can do :

myVar = ++myVar;
// Output 1;

When you’re using ++ or --, the value itself is modified.
So = is not required to assign the value.
The best practice is :

myVar++;
// Output 1.

#3

i did it like this
var myVar = 87;

// Only change code below this line

var a = 1;

var myVar = 87+a++
and the outcome is 88 but it says i had to use the operator++


#4

Yes, you have to use the “best pratice” I wrote above for the exercice.