Sum of two numbers with prompt

后端 未结 8 2482
甜味超标
甜味超标 2020-11-28 14:47

I\'ve been trying to solve this problem for the last couple days: when I subtract, multiply or divide 2 numbers input through a prompt, everything works fine; but when I wan

8条回答
  •  无人及你
    2020-11-28 15:41

    When you enter var a and var b, the variables are probably set strings(characters) and not as integers.

    So, when you use a + b, your'e putting those characters together.

    For ensuring that the value you enter saves as an integer, you can you use the

    parseInt()
    

    For example: var a = parseInt( prompt("Enter first number") );

提交回复
热议问题