Josima
June 10, 2022, 11:21am
1
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;
console.log(myValue);
// 5
myVal++;
console.log(myValue);
// 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.
Josima
June 10, 2022, 11:38am
4
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
Josima
June 10, 2022, 11:40am
5
Thanks. I have now gotten it right.
system
Closed
December 9, 2022, 11:41pm
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.