<html>
<head>
<title> Kalkulator Sederhana </title>
</head>
<body>
<script language="Javascript">
function tambah()
{var bil1 = parseFloat(document.fform.nil1.value);
var bil2 = parseFloat(document.fform.nil2.value);
var hasil= bil1 + bil2;
document.fform.hasil.value= hasil;}
function kurang()
{var bil1 = parseFloat(document.fform.nil1.value);
var bil2 = parseFloat(document.fform.nil2.value);
var hasil = bil1 - bil2;
document.fform.hasil.value= hasil;}
function bagi()
{var bil1 = parseFloat(document.fform.nil1.value);
var bil2 = parseFloat(document.fform.nil2.value);
var hasil= bil1 / bil2;
document.fform.hasil.value= hasil;}
function kali()
{var bil1 = parseFloat(document.fform.nil1.value);
var bil2 = parseFloat(document.fform.nil2.value);
var hasil= bil1 * bil2;
document.fform.hasil.value= hasil;}
function mod()
{var bil1 = parseFloat(document.fform.nil1.value);
var bil2 = parseFloat(document.fform.nil2.value);
var hasil= bil1 % bil2;
document.fform.hasil.value= hasil;
}
</script>
<h1 style = "text-align:center">Kalkulator Sederhana</h1>
<form name = "fform">
<center>
<table>
<tr><td>Nilai 1:</td><td><input type = "text" name = "nil1"/></td></tr>
<tr><td>Nilai 2 : </td><td><input type = "text" name = "nil2"/></td></tr>
<tr>
<td colspan="2" align="center">
<input type = "button" value = "+" onClick = "tambah()"/>
<input type = "button" value = "-" onClick = "kurang()"/>
<input type = "button" value = ":" onClick = "bagi()"/>
<input type = "button" value = "X" onClick = "kali()"/>
<input type = "button" value = "Mod" onClick = "mod()"/>
</td></tr>
<tr><td>Hasil :</td><td><input type = "text" name = "hasil" value=""/></td></tr>
</table><br/>
</center>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar