Berikut ini adalah Script dari Tampilan diatas :
<!DOCTYPE html> <html lang="en"> <head> <title>Kalkulator</title> <script language="JavaScript" type="text/javascript"> function getHasilValue(){ var format = document.kalkulator; var bil1 = parseInt(format.bil1.value); var bil2 = parseInt(format.bil2.value); var operasi = format.operasi.value; var hasil; if(operasi == "jumlah"){ hasil = bil1 + bil2; } else if(operasi == "kurang"){ hasil = bil1 - bil2; } else if(operasi == "kali"){ hasil = bil1 * bil2; } else if(operasi== "bagi"){ hasil = bil1 / bil2; } else{ } format.hasil.value = hasil; } </script> </head> <body bgcolor="white"> <h4>KALKULATOR</h4> <form name="kalkulator" action="#"> Bilangan 1: <input type="text" size="5" maxlength="5" name="bil1"> <br><br> Operasi : <select name="operasi"> <option value="jumlah">+</option> <option value="kurang">-</option> <option value="kali">*</option> <option value="bagi">:</option> </select> <br><br> Bilangan 2: <input type="text" size="5" maxlength="5" name="bil2"> <br><br> <input type="button" value="=" onclick="getHasilValue()"/> <br><br> Hasil : <input type="text" size="10" maxlength="10" name="hasil" readonly> </form> </body> </html>
Tidak ada komentar:
Posting Komentar