BERIKUT ADALAH KODENYA
Silahkan Download Materi Disini
<html>
<head>
<script languange="javascript">
function dicek()
{
a=document.getElementById("aa").value;
b=document.getElementById("bb").value;
c=parseInt(a)+parseInt(b);
d=parseInt(a)-parseInt(b);
e=parseInt(a)/parseInt(b);
f=parseInt(a)*parseInt(b);
var pilih = (document.hitung.pilihan.value);
if(a=="" || b==""){
alert("input masih kosong")
}
if(!(a>=0) || !(b>=0)){
alert("bukan angka")
}
else if((a && b) !==""){
if(pilih=="tambah")
{
document.getElementById("cc").value=c;
}
else if(pilih=="kurang")
{
document.getElementById("cc").value=d;
}
else if(pilih=="bagi")
{
document.getElementById("cc").value=e;
}
else if(pilih=="kali")
{
document.getElementById("cc").value=f;
}
}
}
</script>
</head>
<body>
<form name="hitung">
<input type="text" nama="aa" id="aa">
<select name="pilihan">
<option value="tambah">+</option>
<option value="kurang">-</option>
<option value="kali">*</option>
<option value="bagi">/</option>
</select>
<input type="text" nama="bb" id="bb">
<input type="button" value="=" onClick="dicek()">
<input type="text" nama="bb" id="cc">
</form>
</body>
</html>
HASILNYA AKAN DEMIKIAN
HASILNYA ADALAH SEBAGAI BERIKUT
No comments:
Post a Comment