JavaScript:
function tambah(){
var komponen = document.calc;
var a = parseInt(komponen.a.value);
var b = parseInt(komponen.b.value);
var op = komponen.op.value;
var hasil;
hasil = a + b;
komponen.hasil.value = hasil;
}
function kurang(){
var komponen = document.calc;
var a = parseInt(komponen.a.value);
var b = parseInt(komponen.b.value);
var op = komponen.op.value;
var hasil;
hasil = a - b;
komponen.hasil.value = hasil;
}
function kali(){
var komponen = document.calc;
var a = parseInt(komponen.a.value);
var b = parseInt(komponen.b.value);
var op = komponen.op.value;
var hasil;
hasil = a * b;
komponen.hasil.value = hasil;
}
function bagi(){
var komponen = document.calc;
var a = parseInt(komponen.a.value);
var b = parseInt(komponen.b.value);
var op = komponen.op.value;
var hasil;
hasil = a / b;
komponen.hasil.value = hasil;
}
function hapus(){
var elemen = document.calc;
elemen.a.value = "";
elemen.b.value = "";
elemen.hasil.value = "";
}
kode html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>KALKULATOR</title>
<script language="JavaScript" type="text/javascript" src="Calculator.js"></script>
</head>
<hr color="aqua" width="500px" size="8px" align="left" />
<font size="8" color="Violet" face="Maiandra GD">Java Script Calculator</font>
<hr color="aqua" width="500px" size="8px" align="left" /><br>
<form name="calc" action="#">
<font face="Maiandra GD" color="purple" size=4>Masukkan Bilangan Kesatu =</font><br />
<input type="text" size="25" name="a" /><br>
<font face="Maiandra GD" color="purple" size=4>Masukkan Bilangan Kedua =</font><br />
<input type="text" size="25" name="b" /><br>
<input name="op" type="button" value="+" onclick="tambah()" />
<input name="op" type="button" value="-" onclick="kurang()" />
<input name="op" type="button" value="x" onclick="kali()" />
<input name="op" type="button" value="/" onclick="bagi()" /><br>
<br><font face="Maiandra GD" color="purple" size=4>Hasil</font>
<br><input type="text" size="25" name="hasil" readonly /><br>
<br><input name="op" type="button" value="Hapus" onclick="hapus()" /><br>
</body>
</html>
Tampilan Gambar:
Mar 1, 2011
Subscribe to:
Post Comments (Atom)
0 komentar:
Post a Comment