<html>
<title>Program Kalkulator Sederhana</title>
<SCRIPT LANGUAGE="JavaScript">
function tambah()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.hasil.value = c
}
function kurang()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.hasil.value=c
}
function kali()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.hasil.value=c
}
function bagi()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.hasil.value = c
}
function pangkat()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=Math.pow(a, b)
form.hasil.value = c
}
function kosong()
{
form.a.focus()
form.a.value=""
form.b.value=""
form.hasil.value=""
}
</SCRIPT>
<body onload=kosong()>
<CENTER>
<font size="5">Program Kalkulator</font>
<hr size="5" color="red">
<FORM name="form">
<pre>
Angka 1 <input type="text" name="a">
Angka 2 <input type="text" name="b">
Hasil <input type "text" name="hasil" disabled="true">
</pre>
<hr size="2" color="blue">
<input type="button" value=" + " onClick="tambah()">
<input type="button" value=" - " onClick="kurang()">
<input type="button" value=" x " onClick="kali()">
<input type="button" value=" / " onClick="bagi()">
<input type="button" value=" ^ " onClick="pangkat()"><br>
<input type="button" value=" Kosong " onClick="kosong()">
</FORM>
</CENTER>
</body>
</html>
Tidak ada komentar:
Posting Komentar