0

I have two input fields, see here.

When I add the values (1 and 1), the output is not 2, but 11, why?

Jan Turoň
  • 31,451
  • 23
  • 125
  • 169
Aatmane
  • 27
  • 6
  • Please [don't use images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) on Stack Overflow. Add it as text. You can also create [a runnable Stack Snippet](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) if you prefer. – Ivar Jan 10 '21 at 19:29
  • try - `var sum = parseInt(x) + parseInt(y);` – s.kuznetsov Jan 10 '21 at 19:39
  • I'm sorry bout the code, I tried to write it but doesn't work, I don't know how to do it. And thank you for your answer it's working. – Aatmane Jan 10 '21 at 20:08

1 Answers1

1

Looks like .value is making x and y evaluate to strings, not integers. You could use the pareseInt() function to convert these to integers before adding them together.

parseInt() example usage: https://www.w3schools.com/jsref/jsref_parseint.asp