Increment a Number with JavaScript 5

Increment a Number with JavaScript 5


Tell us what’s happening:

Your code so far

var myVar = 87;

// Only change code below this line
myVar = 86  ;++myVar;

Your browser information:

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

Link to the challenge:


I’ll try my best to give you a hint without telling you the answer:

i++; means the same as i = i + 1;
_____ means the same as myVar = myVar + 1;

Only one line of code is required after the comment.

Hope this helps.

myVar = 86  ;++myVar;

I can see you’ve been trying several things to complete the challenge. Try one thing and then reset to see what works and what doesn’t.

on the first line you have ++myVar which is close but the ++ should be to the right of myVar.

on the second line you have myVar=myVar which is like saying 87=87 which won’t accomplish the increment you’re working for.

Let me know if you have questions about what I said :slight_smile:


‘Let’ is another way to declare your variable. Similar to ‘var’.
Below I have coded a simple “for” Loop. Copy and Paste it into a blank FreeCodeCamp terminal to see it work. It will start at 86 because you declared your ‘myVar’ to equal 86. It will then add ‘1’ to 86 until it reaches 100. It will also print out all the values to your console so you can see and understand how it works. And to solve your problem, code ‘myVar’ to look like ‘i++’. ‘i’ is my variable and ‘++’ is telling Javascript to add ‘1’ to my variable. Hope this helps, let me know if you have any questions. Brad

let myVar = 86;

for (let i =myVar; i <100; i++){