Contoh Coding Kalkulator Sederhana - HariNewss.com

Saturday, November 21, 2020

Contoh Coding Kalkulator Sederhana

 


<!DOCTYPE html>

<html>

<head>

<title>kalkulator</title>

<style type="text/css">

body{

text-align: center;

background-color: blue;

}

</style>

</head>

<body>

<form name = "form">

<h1>KALKULATOR SEDERHANA</h1><br>

<input type="number" name ="pertama"><br>

<label><select name="operator"><label>

<option value="tambah"> + (tambah)</option>

<option value="kurang"> - (kurang)</option>

<option value="kali"> * (kali)</option>

<option value="bagi"> / (bagi)</option>

</select><br>

<input type="number" name = "kedua">

<label ><br>=<br></label>

<input type="text" name = "hasil" disabled="true"><br><br><br>

<input type="button" onclick="hitung()" value="hitung">

</form>

<script >

function hitung(){

var myform = document.form;

var satu = myform.pertama.value;

var dua = myform.kedua.value;

var oper = myform.operator.value;

if (oper == "kali"){

var hoper = satu * dua;

}else if(oper == "kurang"){

var hoper = satu - dua;

}else if(oper == "bagi"){

var hoper = satu / dua;

}else if(oper == "tambah"){

var hoper = satu + dua;

}

myform.hasil.value = hoper;

}

</script>

</body>

</html>


Selamat mencoba

Bagikan artikel ini

Tambahkan Komentar Anda
Disqus comments