Decrement a Number with JavaScript - Help

Hi,

I need help with this test, someone could help me? What’s missing?

Tks

Your code so far


var myVar = 11;

// Only change code below this line
myVar = myVar - 1;
var myVar = 10;
myVar--;
myVar = 10; 
var myVar--;

Your browser information:

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

Link to the challenge:

this is how you do decrement myVar–
in this tutorial myVar is already declared on line 1 . so you don’t need to declare it again
all you have to do is change the value with myVar with myVar-- because “myVar-1” is same as ‘myVar–’

thanks, but still have two test failed messages

Test one is failing because myVar equal 9 as you decrement it twice
Test two is failing as the line you were instructed to change is still there untouched

I think @ilenia is right.

At the end myVar should equal 10 and in this code you are decrementing it twice.

I think the exercise wants you to use myVar-- instead of myVar = myVar - 1

Now I get it! Thanks!

Please have a look at the comments. That’s what your current code is doing. I won’t be giving you the answer straight away. See if you can figure out your error. Please ignore, if you have already solved it.

var myVar = 11; //Initiates the variable myVar with a value of 11

// Only change code below this line
myVar = myVar - 1; //Subtracts 1 from myVar and updates myVar. Hence the value of myVar now is 10
var myVar = 10; //Initializes myVar to 10 again. Previous value(which was 10) is now lost
myVar--; //This is equivalent to subtracting 1 and updating myVar. I am not going into pre and post decrement concepts. Now the value of myVar is 9.
myVar = 10;  //Updates myVar to 10 again. Previous value(which was 9) is now lost
var myVar--; //This is a syntax error. var is a keyword you use to initlalize a variable and myVar-- is a decrement operation. You shouldn't be using var here.