Increment a number with javascript myVar please help

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

var myVar = 87;

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

Your browser information:

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

Challenge: Increment a Number with JavaScript

Link to the challenge:

myVar = myVar ++;

It’s an oddity of the increment operator that if you put it after the variable, it will evaluate it after it is referenced. So, it is evaluating the right side, but it assigns the value to the left side before the increment and the incremented value is discarded.

There are two ways to fix that. First, you could put the ++ before the variable name.

Or, you don’t need an assignment - you can just increment the variable. In other words, you don’t need the first half, the myVar = . For example, if I wanted to decrement a variable called “count”, I could just have:


as its own line. I assume that that was what the exercise want’s you to do. There is no advantage to the first option.

Does that make sense?

got it, thanks :grinning: :grinning: :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.