Basic JavaScript: Decrement a Number with JavaScript

Basic JavaScript: Decrement a Number with JavaScript
0

#1

INSTRUCTIONS:
myVar should equal 10
myVar = myVar - 1; should be changed
Use the – operator on myVar
Do not change code above the line

ORIGINAL CODE:
var myVar = 11;

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

MY SOLUTION:

var myVar = 11;

// Only change code below this line
myVar–

RESULTS:
All tests passed except for “myVar = myVar - 1; should be changed.” I did change it. Why isn’t the test passing?


#2
Myvar = Myvar+1 

That’s the same as saying Myvar +=1. Now how could you do that but minus?


#3

You should only be modifying the line below and not adding any other code above or below this line.

myVar = myVar - 1;

Just change the above line to use the -- operator on myVar.

The code you posted shows two lines duplicate lines of:

var myVar = 11;

and you still have the original line of code which you were supposed to just modify (see below);

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

#4

Hi, Randell. I was just illustrating the original code and my solution. I didn’t combine them, nor did I add any code above the line.

This is my final solution, and it doesn’t pass the test “myVar = myVar - 1; should be changed.”

var myVar = 11;

// Only change code below this line
myVar–


#5

I had trouble figuring out what you actually were using based on the information you posted.

Your latest posted code would pass if you put a semi-colon after the -- operator. If it does not pass, make sure you are using Chrome and not Edge or Safari.


#6

I forgot the semicolon. Thanks, Randell.