JavaScript problem about calculation and concatenation

Viewed 29

Whenever am adding the calculation part at middle of ALERT,, its showing me unexpected output. I entered DOG AGE as 5yrs but its showing output as 1221 . Check first picture. but when am entering the calculation part at the starting,, its showing me correct result. check second image. why is so??

image1

image2

1 Answers

You are not adding brackets around the calculation. So, it is calculating only (dogage-2)*4 and appending 21 to the output. Below works

alert("your dog age is :" + ((dogage-2)*4+21) +" yrs old in human age");
Related