# Javascript calculator with basic arithmetic operations

Last updated on March 1st, 2022 at 12:07 pm

Click to rate this tutorial!
[Total: 39 Average: 3.8]

### Javascript calculator with basic arithmetic operations

This is a simple javascript that performs basic arithmetic operations like Addition, Subtraction, Division, Multiplication and Modulus. Just copy paste the below script in to an html file and run on any browser to see the working.

```<title>Javascript calculator with basic arithmetic operations
</title><script language="javascript" type="text/javascript">
function multiply(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a*b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a+b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function subtraction(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a-b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function division(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a/b;
document.my_cal.total.value=c;
}
</script>

<script language="javascript" type="text/javascript">
function modulus(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a%b;
document.my_cal.total.value=c;
}
</script>

<!-- Opening a HTML Form. -->
<form name="my_cal">

<!-- Here user will enter 1st number. -->
Number 1: <input type="text" name="first">

<!-- Here user will enter 2nd number. -->
Number 2: <input type="text" name="second">

<!-- Here result will be displayed. -->
Get Result: <input type="text" name="total">