Write a JavaScript to add two numbers read from user.
Solution:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Addition of Two Numbers</title>
</head>
<body>
<script type="text/javascript">
var num1 = window.prompt("Enter first number::");
var num2 = window.prompt("Enter second number::");
var sum = parseInt(num1) + parseInt(num2);
document.write("Sum of "+num1+" and "+num2+" is "+sum);
</script>
</body>
</html>
Output:<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Addition of Two Numbers</title>
</head>
<body>
<script type="text/javascript">
var num1 = window.prompt("Enter first number::");
var num2 = window.prompt("Enter second number::");
var sum = parseInt(num1) + parseInt(num2);
document.write("Sum of "+num1+" and "+num2+" is "+sum);
</script>
</body>
</html>