Senin, 07 Maret 2011

Tugas Praktikum Modul 5 (kalkulator)


Scirpt:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Studi Kasus</title> 

</head>
<body>

<script language="JavaScript" type="text/javascript">
 <!--
  function hitung(){
   var kalkulator = document.form1;
   var a=eval(kalkulator.a.value);
   var b=eval(kalkulator.b.value);
   var operasi= kalkulator.opt.value;
  if (operasi == "penjumlahan") {
   var c = a + b;
  }else if (operasi == "pengurangan") {
   var c = a - b;
  } else if (operasi == "perkalian") {
   var c = a * b;
  } else if (operasi == "pembagian") {
   var c = a / b;
  }
   kalkulator.hasil.value = c;
  }
  function resetForm(){
   document.form1.reset();
  }
  //-->
</script>
<center>
<h4 font size= "5"> Simple Calculator</font></h4>
 <form name="form1" action="#">
 <input type="text" name="a" />
<select name="opt">
 <option value="penjumlahan"> + </option>
 <option value="pengurangan"> - </option>
 <option value="perkalian"> * </option>
 <option value="pembagian"> / </option>
</select>

<input type="text" name="b" />
<input type="button" value="=" onClick="hitung()" />
<input type="text" name="hasil" disabled="true" /> <br/>
<p>
<p>
<input type="button" value="Clear" onClick="resetForm()" />
</form>
</body>
</html>
HASIL :

Tidak ada komentar:

Posting Komentar