Tags

, , ,

Kali ini gue mau bikin tulisan tentang bikin kalklator sederhana pake JavaScript… Gampang ko bikinnya…. Langsung aja cek source nya…

<html>
<title>Kalkulator Java Script</title>
<head>
<script language="javascript">
function hitung(a, b, parameter){
 if (parameter==1){
 var hasil=parseInt(a) + parseInt(b);
 document.writeln ("Hasil Penjumlahan : "+a+" + "+b+" = "+hasil);
 } else if (parameter==2){
 var hasil=a-b;
 document.writeln ("Hasil Pengurangan : "+a+" - "+b+" = "+hasil);
 } else if (parameter==3){
 var hasil=a*b;
 document.writeln ("Hasil Perkalian : "+a+" x "+b+" = "+hasil);
 } else if (parameter==4){
 var hasil=a/b;
 document.writeln ("Hasil Pembagian : "+a+" : "+b+" = "+hasil);
 } else if (parameter==5){
 var hasil=a%b;
 document.writeln ("Hasil Penjumlahan : "+a+" % "+b+" = "+hasil);
 }
}
</script>
</head>
<body>
<form name="form1">
 <table name="tabel">
 <tr>
 <td>Bilangan A :</td>
 <td><input type="text" name="a"/></td>
 </tr>
 <tr>
 <td>Bilangan B :</td>
 <td><input type="text" name="b"/></td>
 </tr>
 <tr>
 <td></td>
 <td>
 <input type="button" onclick="hitung(document.form1.a.value, document.form1.b.value, 1)" name="tambah" value="Tambah"/>
 <input type="button" onclick="hitung(document.form1.a.value, document.form1.b.value, 2)" name="kurang" value="Kurang"/>
 <input type="button" onclick="hitung(document.form1.a.value, document.form1.b.value, 3)" name="kali" value="Kali"/>
 <input type="button" onclick="hitung(document.form1.a.value, document.form1.b.value, 4)" name="bagi" value="Bagi"/>
 <input type="button" onclick="hitung(document.form1.a.value, document.form1.b.value, 5)" name="modulus" value="Modulus"/>
 </td>
 </tr>
 </table>
</form>
</body>
</html>
Advertisements