1

I want to add 52 to the value of a variable I have.

So in principle:

Var chicken = eggs+52

Eggs being 100, so chicken then becomes 152...

Current method is not working. Any ideas?

3 Answers 3

1

Use .parseInt() in Javascript

var chicken = parseInt(eggs, 10) + 52;
Sign up to request clarification or add additional context in comments.

3 Comments

Var V as Upper Case is a typo.
Thanks Subir Kumar Sao
This might not be the issue, the first problem is the syntax error Var.
0

You have a syntax error. Var should be var because JavaScript is case sensitive.

Also you might need to cast eggs as a number, if it is currently a string:

var chicken = +eggs + 52; // the +eggs casts as a number

Remember to check the developer console (F12) when debugging, because usually there is an error pointing to the problem.

Comments

0

I doubt that eggs is not a type of Number.

You can parse it like,

var chicken = parseInt(eggs,10)+52;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.