Selasa, 01 Maret 2011

Studi Kasus Modul 5 part 2

<title>Kalkulator GJ</title>
<script language="JavaScript">


function tambah()
{
a=parseInt(form.a.value)
b=parseInt(form.b.value)
c=a+b
form.hasil.value=c
}

function kurang()
{
a=parseInt(form.a.value)
b=parseInt(form.b.value)
c=a-b
form.hasil.value=c
}

function kali()
{
a=parseInt(form.a.value)
b=parseInt(form.b.value)
c=a*b
form.hasil.value=c
}

function bagi()
{
a=parseInt(form.a.value)
b=parseInt(form.b.value)
c=a/b
form.hasil.value = c
}

function pangkat()
{
a=parseInt(form.a.value)
b=parseInt(form.b.value)
c=Math.pow(a, b)
form.hasil.value = c
}

function RESET()
{
form.a.focus()
form.a.value=""
form.b.value=""
form.hasil.value=""

}

</SCRIPT>

<body onload=kosong()>
<h1><strong><font color="Blue"> <font size="5"> Kalkulator</strong></font></h1>

<form name="form">
<pre>
Angka a <input type="text" name="a"></br>
Angka b <input type="text" name="b">
</pre>
<input type="button" value=" x " onClick="kali()">
<input type="button" value=" / " onClick="bagi()">
<input type="button" value=" + " onClick="tambah()">
<input type="button" value=" - " onClick="kurang()">
<input type="button" value=" ^ " onClick="pangkat()">
<input type="button" value=" RESET " onClick="RESET()">

Hasil <input type "text" name="hasil" disabled="true">



</form>

</body>
</html>

Hasilnya :

Tidak ada komentar:

Posting Komentar