Tuesday, March 1, 2011

tugas modul 5



--------------------------------------------------------------------
tugas01.js
-------------------------------------------------------------------
function kalkulator(){
    var bagian = document.hitung;
    var angka = parseInt(bagian.angka.value);
    var bilangan = parseInt(bagian.bilangan.value);  
    var operasi = bagian.operasi.value;
    var hasil;
  
    if(operasi == "jumlah"){
        hasil = angka + bilangan;
    }
    else if(operasi == "kurang"){
        hasil = angka - bilangan;
    }
    else if(operasi == "kali"){
        hasil = angka * bilangan;
    }
    else{
        hasil = angka / bilangan;
    }
  
    bagian.hasil.value = hasil;
}

------------------------------------------------
tugas 1.html
------------------------------------------------
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>kalkulator</title>
        <script language="JavaScript" type="text/javascript" src="tugas 1.js"></script>
    </head>
    <body background=back.png>
        <center>
            <form name="hitung" action="#">
            <h2><font color = yellow size= "45" face = "Monotype Corsiva" > Kalkulator </font></h2>
                <input type="text" size="3" name="angka">
                <br><br><select name="operasi">
                    <option value="jumlah">+</option>
                    <option value="kurang">-</option>
                    <option value="kali">*</option>
                    <option value="bagi">:</option>
                </select>
                <br><br><input type="text" size="3" name="bilangan">
                <br><br><input type="button" value="=" onclick="kalkulator()"/>
                <br><br><input type="text" size="10" name="hasil" readonly>
            </form>
        </center>
    </body>
</html>

No comments:

Post a Comment