Basic JavaScript - Decrement a Number with JavaScript

Tell us what’s happening:
The first code after the comment looks okay, it’s the second code that i’m not sure about…

Your code so far

let myVar = 11;

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

Your browser information:

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

Challenge: Basic JavaScript - Decrement a Number with JavaScript

Link to the challenge:

You only need one line of code. Also, in that one line of code, you don’t need to reassign with an equals sign. That’s the whole point of the decrement

1 Like

It’s better to decrement it directly like

Let MyVar = 11;
MyVar--; // and to be useful, it should be in a function connected to an event 
1 Like

The codes after the comment are wrong. The operator in use here is the decrement operator --. Therefore, all you need is myVar --;. When expanded, the code looks like this;

myVar = myVar - 1;

The decrement operator handles both decreasing the value of the operand by one and reassigning that value to the operand

1 Like

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