Calculator Help


I am trying to make a calculator for fun but when I prompt for numbers on both add and subtract. The data is held like a string rather than a number. There are no syntax errors.

var answer1 = prompt('What is the first number?');
var answer2 = prompt('What is the second number?');
var addition = function(number1, number2) {
   console.log('Your answer is:')
   console.log(number1 + number2);


And what is the problem?


When i try to add the two prompted numbers they just are put together like strings instead of numbers. I want 4 + 6 to = 10 not 46


The number data type has that property. Can you turn a string into a number?


You can use the
"Number()" method to convert the output to "numbers" at call
e.g addition(Number(answer1), Number(answer2));


Thanks a lot, but where in the code would that go?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.