Skip to content

Instantly share code, notes, and snippets.

@bonaxcrimo
Created November 8, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonaxcrimo/c136f5304faf2a89d87dc2bc6ad2deb3 to your computer and use it in GitHub Desktop.
Save bonaxcrimo/c136f5304faf2a89d87dc2bc6ad2deb3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Alert</title>
</head>
<body>
<input type="text" name="" id="bil1">
<input type="text" name="" id="bil2">
<button onclick="oper(0)">+</button>
<button onclick="oper(1)">-</button>
<button onclick="oper(2)">*</button>
<button onclick="oper(3)">/</button>
<p id="hasil"></p>
<script type="text/javascript">
function oper(n){
var hasil;
var bil1=parseInt(document.getElementById("bil1").value);
var bil2=parseInt(document.getElementById("bil2").value);
if(n==0)
hasil=bil1+bil2;
else if(n==1)
hasil=bil1-bil2;
else if(n==2)
hasil=bil1*bil2;
else
hasil=bil1/bil2;
document.getElementById("hasil").innerHTML=hasil;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment