How do I restrict user input to only numbers in Javascript?
I'm new to javascript, so pardon my syntax. I am trying to create a 2 number alert box calculator in Javascript, other functions work fine except that Addition, e.g Instead of 1 + 3 = 4, it returns 13 instead (concatenation), would really appreciate if I can be shown what I'm doing wrong. Here's the code below: function addNum(){ var result = a + b; alert (result); } function subtractNum(){ var result = a - b; alert (result); } function multiplyNum(){ var result = a * b; alert (result); } function divideNum(){ var result = a / b; alert (result); } var calc = prompt ( "Choose any of these options for your calculation: \n'+' for Addition \n'-' for Subtraction \n'*' for Multiplication \n'/' for Division "); if (calc === "+"){ var a = prompt ("Enter first number: " ) var b = prompt ("Enter second number: " ) addNum(); } else if (calc === "-") { var a = prompt ("Enter first number: " ) var b = prompt ("Enter second number: " ) subtractNum(); } else if (calc === "*") { var a = prompt ("Enter first number: " ) var b = prompt ("Enter second number: " ) multiplyNum(); } else if (calc === "/") { var a = prompt ("Enter first number: " ) var b = prompt ("Enter second number: " ) divideNum(); } else{ alert("System could not perform operation") }