-2

So im quite new to javascript and i tried making something simple as entering a value and add 150 to it but it wont show number + 150? Pictures below

Code

Output

2 Answers2

0

Because you're actually concatenating a string with a number. The input value is a string, so before operating with it, parse it to int with parseInt

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Javier S
  • 339
  • 3
  • 10
0

That's because you are concatenating strings. You need to convert the strings to integers by using parseInt(), and then add the numbers.

https://www.w3schools.com/jsref/jsref_parseint.asp

var fullprice = parseInt(price) + 150;
Gregory R.
  • 1,665
  • 1
  • 18
  • 30