Add Two Number Program in JavaScript
Advertisements
Find Sum of Two Numbers Using JavaScript
Example
<!doctype html>
<html>
<head>
<script>
function add(){
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a + b;
document.getElementById("answer").value= c;
}
</script>
</head>
<body>
Enter the First number : <input id="first">
Enter the Second number: <input id="second">
<button onclick="add()">Add</button>
<input id="answer">
</body>
</html>
Result
Enter First Number:
Enter Second Number:
Enter Second Number:
Code Explanation
- no=Number(document.getElementById("first").value);
This code is used for receive first input value form input field which have id first. - no=Number(document.getElementById("second").value);
This code is used for receive first input value form input field which have id second. - document.getElementById("answer").value= fact;
This code is used for receive calculated value of factorial and display in input field which have id answer - <button onclick="add()">Add</button>
This code is used for call add function when button clicked.
Google Advertisment
