Write a javascript program to make a simple calculator
Answer Posted / sara
<html>
<script type="text/javascript">
function abc1()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(1)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(1)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc2()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(2)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(2)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc3()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(3)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(3)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc4()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(4)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(4)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc5()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(5)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(5)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc6()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(6)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(6)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc7()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(7)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(7)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc8()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(8)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(8)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc9()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(9)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(9)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc0()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(0)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(0)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abcdiv()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(4)
document.tp.tk7.value=ad
}
function abcadd()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(1)
document.tp.tk7.value=ad
}
function abcsub()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(2)
document.tp.tk7.value=ad
}
function abcmul()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(3)
document.tp.tk7.value=ad
}
function abcreset()
{
a=parseInt(1)
document.tp.tk3.value=a
document.tp.tk1.value=0
document.tp.tk2.value=0
document.tp.tk4.value=0
document.tp.tk7.value=0
}
function abcanswer()
{
if((document.tp.tk7.value)==1)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)
+parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==2)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)-
parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==3)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)
*parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==4)
{
document.tp.tk4.value=parseInt
(document.tp.tk1.value)/parseInt(document.tp.tk2.value)
}
}
function abcnext()
{
a=parseInt(2)
document.tp.tk3.value=a
}
</script>
<h3 align="center">
<form name=tp>
<input type=text name=tk1 value="0"><br/>
<input type=text name=tk2 value="0"><br/>
<input type=text name=tk4 value="0"><br/>
<input type=hidden name=tk3 value="1"><br/>
<input type=hidden name=tk7 value="0"><br/>
<input type="button" onclick=abc1() value="1">
<input type="button" onclick=abc2() value="2">
<input type="button" onclick=abc3() value="3"><br/>
<input type="button" onclick=abc4() value="4">
<input type="button" onclick=abc5() value="5">
<input type="button" onclick=abc6() value="6"><br/>
<input type="button" onclick=abc7() value="7">
<input type="button" onclick=abc8() value="8">
<input type="button" onclick=abc9() value="9"><br/>
<input type="button" onclick=abc0() value="0"><br/>
<input type="button" onclick=abcadd() value="add">
<input type="button" onclick=abcsub() value="sub">
<input type="button" onclick=abcmul() value="mul">
<input type="button" onclick=abcdiv() value="div"><br/>
<input type="button" onclick=abcanswer() value="answer">
<input type="button" onclick=abcreset() value="reset">
</form>
</body>
</html>
| Is This Answer Correct ? | 7 Yes | 16 No |
Post New Answer View All Answers
Which built-in method combines the text of two strings and returns a new string?
What is difference between undefined variable and undeclared variable?
What is the use of blur function?
What is ‘this’ keyword in JavaScript?
How can a value be appended to an array?
What are undefined and undeclared variables?
What web sites do you feel use javascript most effectively (i.e., Best-in-class examples)? The worst?
Name the types of functions.
What is primitive data types in javascript?
Do you have to declare variables in javascript?
How many types of variables are there in javascript?
What is callback in javascript?
What is difference between local and global scope in javascript ?
What is the scope variable in javascript?
Can you explain the difference between == and ===?