Thursday 4 February 2021

Use Arithmetic operator in JavaScript

 

Use Arithmetic operator in JavaScript

Arithmetic operator is a simple operator that are used in human life like addition, subtraction, multiplication, division, and mode. individually when any person moves in society and make some inventory event and calculate area of any filed or mapping any distance and take weight then use arithmetic operator. if any shopper sale or purchase any item then use arithmetic operator. In lower classes student learn in math's subject use of arithmetic operator. Arithmetic operators are used to perform arithmetic operations. Following are the arithmetic operators used in JavaScript Language?
OperatorMeaningExampleResult
+addition5+27
-subtraction5-23
xMultiplication5x210
/division5/22
%Modulus5%21


How use arithmetic operator in JavaScript with in HTML programs

In the JavaScript arithmetic operators are used to calculate a variable value
Within JavaScript tag.when  JavaScript file write separately and save with extension .js
then add it in html program by lik tag as like
<link rel="javascript" type="text/javascript" href="tpe full with name and extension of javascript file/>
Or you can use JavaScript tag with html file under the header tags
here we give some example to using arithmetic operators for arithmetic operations

Example 1

Open note pad and type fallowing code save with .HTML extension and open with any web browser.
Look JavaScript code 
<Script>
var  number1=10;
var number2=20;
var sum=number1+number2;
var mul=number1*number2
var sub=number1-number2;
var div=number1/number2;
var mod=number1/number1;
document.write("sum fo two number="+sum );
document.write("</br>Multiplication of two number="+mul);
document.write("</br>Division of two number="+div);
document.write("</br>Substraction of two number="+sub);
document.write("</br>Mode of two number="+mod);
</Script>

output look like this

sum fo two number=30
Multiplication of two number=200
Division of two number=0.5
Substraction of two number=-10
Mode of two number=1

Example 2

Open note pad and type fallowing code save with .HTML extension and open with any web browser.
<html>
<head>
<title>arithmetic operations.</title>

<Script type="text/javascript">
function makeresult()
{
var  number1=Number(document.getElementById("one").value);
var number2=Number(document.getElementById("two").value);
var sum=number1+number2;
var mul=number1*number2;
var sub=number1-number2;
var div=number1/number2;
var mod=number1/number2;
document.getElementById("summ").value=sum;
document.getElementById("mull").value=mul;
document.getElementById("divv").value=sub;
document.getElementById("subb").value=div;
document.getElementById("modd").value=div;

}
</Script>
</head>
<body bgcolor="green">
<center>
<table border="5" bgcolor="yellow">
<form  method="GET" action="index.html">
<tr><td colspan="2" align="center" >Arithmetic operations.</td></tr>
<tr><td>Enter the frist Number</td><td><input type="text" id="one" name="one"/></td></tr>
<tr><td>Enter the second Number</td><td><input type="text" id="two" name="two"/></td></tr>
<tr><td align="right">Result:</td><td><input type="text" id="summ" name="summ"/></td></tr>
<tr><td align="right">Result:</td><td><input type="text" id="mull" name="mull"/></td></tr>
<tr><td align="right">Result:</td><td><input type="text" id="subb" name="subb"/></td></tr>
<tr><td align="right">Result:</td><td><input type="text" id="divv" name="divv"/></td></tr>
<tr><td align="right">Result:</td><td><input type="text" id="modd" name="modd"/></td></tr>
<tr><td align="center" colspan="2" align="center"><input type="button" value="calculate" onclick="makeresult()"/></td></tr>
</form>
<table>
</body>
</html>

OUT PUT OF THIS PROGRAMS


0 comments:

Post a Comment