Five function calculator

JavaScript

Here is a really simple JavaScript calculator – with just 5 functions! (Add, subtract, multiply, divide, and power) This example can help you see how JavaScript evaluates math functions! Check it out!

 

<!-- TWO STEPS TO INSTALL 5 FUNCTION CALCULATOR:
 
   1.  Paste the coding into the HEAD of your HTML document
   2.  Add the last code into the BODY of your HTML document  -->
 
<!-- STEP ONE: Copy this code into the HEAD of your HTML document  -->
 
<head>
 
<script LANGUAGE="JavaScript">
 
<!-- Original: Rick Johnson -->
<!-- Web Site:  http://members.tripod.com/~RickJohnson -->
 
<!--Total Java Scripts 99 - Next Step Software-->
 
<!-- Begin
function a_plus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.ans.value = c
}
function a_minus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value=c
}
function a_times_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.ans.value=c
}
function a_div_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
}
function a_pow_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=Math.pow(a, b)
form.ans.value = c
}
// End -->
</script>
 
<!-- STEP TWO: Put this code into the BODY of your HTML document  -->
 
<body>
<center>
<form name="formx"><input type=text size=4 value=12 name="a">
<input type="button" value="  +  " onClick="a_plus_b(this.form)">
<input type="button" value="  -  " onClick="a_minus_b(this.form)">
<input type="button" value="  x  " onClick="a_times_b(this.form)">
<input type="button" value="  /  " onClick="a_div_b(this.form)">
<input type="button" value="  ^  " onClick="a_pow_b(this.form)">
<input type="number" size=4 value=3 name="b"> = <input type "number" value=0 name="ans" size=9>
</form>
</center>
 
<!-- Script Size:  1.72 KB  -->

 

M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post