Home Tutorial Javascript JavaScript determine add, product of two numbers

 
 

Share on Google+Share on Google+
JavaScript determine add, product of two numbers
Posted on: August 12, 2010 at 12:00 AM
Advertisement
In this section, you will learn how to determine addition, multiplication, division and modulus of two numbers.

JavaScript determine add, product of two numbers

In this section, you will learn how to determine addition, multiplication, division and modulus of two numbers. To find this, we have created two textboxes and four button for the corresponding functions. As the user clicks the button after entering the bumbers in their respective textboxes, the result will get displayed through the alert box.

Here is the code:

<html>
<
script>
function
add(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var sum=Number(num1)+Number(num2);
alert("Sum of two numbers is: "+sum);
}
function divide(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var sum=Number(num1)/Number(num2);
alert("Result is: "+sum);
}
function product(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var sum=Number(num1)*Number(num2);
alert("Product is: "+sum);
}
function modulus(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var sum=Number(num1)%Number(num2);
alert("Modulus is: "+sum);
}
</script>
<
form name="form">
<
table>
<
tr>
<
td>Enter First Number:</td>
<
td><input type="text" name="text1"></td>
</
tr>
<
tr>
<
td>Enter Second Number:</td>
<
td><input type="text" name="text2"></td>
</
tr>
<
tr>
<
td><input type="button" value="Add" onclick="add();"></td>
<
td><input type="button" value="Divide" onclick="divide();"></td>
</
tr>
<
tr>
<
td><input type="button" value="Product" onclick="product();"></td>
<
td><input type="button" value="Modulus" onclick="modulus();"></td>
</
tr>
</
table>
</
html>

Output:

On clicking the 'Add' button, result will get displayed:

Advertisement

Related Tags for JavaScript determine add, product of two numbers:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com