I just want to add two numbers in javascript using prompt but the output comes as a string.
var num1 =prompt("enter a number");
var num2=prompt("enter a number");
var sum =num1+num2;
console.log(`the of ${num1} and ${num2} ${sum} `);
I just want to add two numbers in javascript using prompt but the output comes as a string.
var num1 =prompt("enter a number");
var num2=prompt("enter a number");
var sum =num1+num2;
console.log(`the of ${num1} and ${num2} ${sum} `);
The return type of prompt
is string
so it is needed to convert string to number to do sum
operation.
var num1 = Number(prompt("enter a number"));
var num2 = Number(prompt("enter a number"));
var sum =num1 + num2;
console.log(`the of ${num1} and ${num2} ${sum} `);