STUDI KASUS KALKULATOR
<!DOCTYPE html> <html lang="en"> <head> <title>>>>Simple Calculator<<<</title> <span id="preserve576a6cbbe98345ef8f29fabd10782348" class="wlWriterPreserve"><script language="JavaScript" type="text/javascript" src="calc.js"></script></span> </head> <body> <hr color=#8b8bf5 width="330px" size="5px" align="left" /> <font size="4" color="blue">>>>Simple Kalkulator<<<</font> <hr color=#8b8bf5 width="330px" size="5px" align="left" /> <hr color=#8b8bf5 width="330px" size="5px" align="left" /> <form name="calc" action="#"> Input 1 <input type="text" size="25" name="bil1" /><br> Input 2 <input type="text" size="25" name="bil2" /><br> <input name="hsl" type="radio" onclick="penjumlahan()" />+ <input name="hsl" type="radio" onclick="pengurangan()" />- <input name="hsl" type="radio" onclick="perkalian()" />x <input name="hsl" type="radio" onclick="pembagian()" />/<br> <br>Hasil <input type="text" size="25" name="hasil" readonly /><br> <br><input name="hsl" type="button" value="Reset" onclick="bersih ()" /><br> <hr color=#8b8bf5 width="330px" size="5px" align="left" /> </body> </html>
function pengurangan(){ var komponen = document.calc; var bil1 = parseInt(komponen.bil1.value); var bil2 = parseInt(komponen.bil2.value); var hsl = komponen.hsl.value; var hasil; hasil = bil1 - bil2; komponen.hasil.value = hasil; } function penjumlahan(){ var komponen = document.calc; var bil1 = parseInt(komponen.bil1.value); var bil2 = parseInt(komponen.bil2.value); var hsl = komponen.hsl.value; var hasil; hasil = bil1 + bil2; komponen.hasil.value = hasil; } function perkalian(){ var komponen = document.calc; var bil1 = parseInt(komponen.bil1.value); var bil2 = parseInt(komponen.bil2.value); var hsl = komponen.hsl.value; var hasil; hasil = bil1 * bil2; komponen.hasil.value = hasil; } function pembagian(){ var komponen = document.calc; var bil1 = parseInt(komponen.bil1.value); var bil2 = parseInt(komponen.bil2.value); var hsl = komponen.hsl.value; var hasil; hasil = bil1 / bil2; komponen.hasil.value = hasil; } function bersih(){ var elemen = document.calc; elemen.bil1.value = ""; elemen.bil2.value = ""; elemen.hasil.value = ""; }
TAMPILAN
0 komentar:
Posting Komentar