0% found this document useful (0 votes)
7 views2 pages

JavaScript Addition Program Example

Uploaded by

Prema Ranganath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

JavaScript Addition Program Example

Uploaded by

Prema Ranganath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Javascript

<!doctype html>

<html>

<head>

<title>Adding two numbers using JavaScript in HTML</title>

<script>

var num1 = 10;

var num2 = 40;

var sum = num1+num2;

[Link]("Sum of two numbers is " + sum);

</script>

</head>

<body></body>

</html>

JavaScript Program to Add Two Numbers Using Form


and TextBox
Let us see the actual JavaScript program that lets the user give the input using Form and
Textbox.

<!doctype html>

<html>

<head>

<script>

function add()

var num1, num2, sum;

num1 = parseInt([Link]("firstnumber").value);

num2 = parseInt([Link]("secondnumber").value);

sum = num1 + num2;


[Link]("answer").value = sum;

</script>

</head>

<body>

<p>First Number: <input id="firstnumber"></p>

<p>Second Number: <input id="secondnumber"></p>

<button onclick="add()">Add Them</button>

<p>Sum = <input id="answer"></p>

</body>

</html>

Output:

You might also like