This tutorial will explain about javascript function to add two numbers with example. Create a web form that has two input fields and a button.
The user can type intro two numbers and when she clicks on a button, the page will show the sum of the numbers.
Addition of Two Numbers Using jQuery
Here JavaScript Code Snippet – Add two integer numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 | var input1 = window.prompt("Enter a number: ", 0); var input2 = window.prompt("Enter another number: ", 0); var input3 = window.prompt("Enter another number: ", 0); var value1 = parseFloat(input1) + parseFloat(input2); var value3 = parseFloat(input3); var sum = sum1(value1 , value3); document.writeln(" <h1>First number: " + value1 + "</h1> "); document.writeln(" <h1>Second number: " + value3 + "</h1> "); document.writeln(" <h1>Sum: " + sum + "</h1> "); function sum1 (x,y) { return (x+y); } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.