Decrement Value Challenge has not worked despite me thinking I have done as instructed. Why is this?

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

Your code so far

let myVar = 11;

// 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/101.0.4951.67 Safari/537.36

Challenge: Decrement a Number with JavaScript

Link to the challenge:

myVar = myVar --;

This doesn’t do what you think it does. First of all, you don’t need an assignment, it does it in place. So,

let myValue = 5;
// 5
// 6

So, what is happening in your statement? You are using the post decrement, so it evaluates the myVar and stores it in myVar, then it decrements myVar. It’s not quite what was asked.

myVar= myVar -1 is equivalent to myVar - -
That’s why your code is not working. You are doing myVar = myVar - - which is wrong.

I fail to understand. I have learnt that if I have

let myVar=11

myVar = myVar – should give me a new value of myVar=10

However for my case it has not been the case

Thanks. I have now gotten it right.

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