Itung.Js
function itung(){
var komponen = document.calc;
var bil1 = parseInt(komponen.bil1.value);
var bil2 = parseInt(komponen.bil2.value);
var op = komponen.op.value;
var hasil;
if(op == "add"){
hasil = bil1 + bil2;
}
else if(op == "sub"){
hasil = bil1 - bil2;
}
else if(op == "mpy"){
hasil = bil1 * bil2;
}
else{
hasil = bil1 / bil2;
}
komponen.hasil.value = hasil;
}
Kalkulator.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kalkulator</title>
<script language="JavaScript" type="text/javascript" src="itung.js"></script>
</head>
<body bgcolor="gray">
<center>
<h3>Tugas Praktikum</h3>
<form name="calc" action="#">
<input type="text" size="5" name="bil1">
<select name="op">
<option value="add">+</option>
<option value="sub">-</option>
<option value="mpy">x</option>
<option value="div">/</option>
</select>
<input type="text" size="5" name="bil2">
<input type="button" value="=" onclick="itung()"/>
<input type="text" size="10" name="hasil" readonly>
</form>
</center>
</body>
</html>
Hasil
Langganan:
Posting Komentar (Atom)
0 Response to "Tugas Praktikum"
Posting Komentar