Basic JavaScript - Increment a Number with JavaScript

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

let myVar ++ 87;

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

Your browser information:

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

Challenge Information:

Basic JavaScript - Increment a Number with JavaScript

Hey @nhymfa31
When you declare a variable in JS you have to assign a value to it using the assignment operator otherwise it will be undefined so like what is happening here you are incrementing an undefined variable.

This will result to NaN
so just assign the variable to a value like so

var a=23;

Then you can increment the value,either by doing this

a = a + 1;

Happy coding

3 Likes

Welcome to the community @nhymfa31 !

I believe the lesson wishes us to use the increment operator

You can easily increment or add one to a variable with the ++ operator.

For example as taken from the lesson.
i = i + 1
would be equivalent to i++
using the increment operator.
This removes the need for the =

I hope this helps you.

1 Like