Created
April 13, 2020 15:40
-
-
Save knightazura/65ee07dbde2e797acf9c8e2db4ea5770 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/dafuwef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input type="text" id="input-1" placeholder="Input 1"> | |
<input type="text" id="input-2" placeholder="Input 2"> | |
<div class="output">Output: #</div> | |
<label for="tambah"> | |
<input type="radio" id="tambah" name="operasi" value="+" checked> | |
tambah | |
</label> | |
<label for="kurang"> | |
<input type="radio" id="kurang" name="operasi" value="-"> | |
kurang | |
</label> | |
<label for="kali"> | |
<input type="radio" id="kali" name="operasi" value="*"> | |
kali | |
</label> | |
<label for="bagi"> | |
<input type="radio" id="bagi" name="operasi" value="/"> | |
bagi | |
</label> | |
<button id="hitung">Hitung</button> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<script id="jsbin-javascript"> | |
$("#hitung").click(function () { | |
var input_1 = $("#input-1").val() | |
var input_2 = $("#input-2").val() | |
input_1 = parseInt(input_1, 10) | |
input_2 = parseInt(input_2, 10) | |
var operator = $("[name=operasi]:checked").val() | |
var hasil = null | |
switch(operator) { | |
case "+": | |
hasil = input_1 + input_2 | |
break; | |
case "-": | |
hasil = input_1 - input_2 | |
break; | |
case "*": | |
hasil = input_1 * input_2 | |
break; | |
case "/": | |
hasil = input_1 / input_2 | |
break; | |
} | |
$(".output").html(`Output: ${hasil}`) | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">$("#hitung").click(function () { | |
var input_1 = $("#input-1").val() | |
var input_2 = $("#input-2").val() | |
input_1 = parseInt(input_1, 10) | |
input_2 = parseInt(input_2, 10) | |
var operator = $("[name=operasi]:checked").val() | |
var hasil = null | |
switch(operator) { | |
case "+": | |
hasil = input_1 + input_2 | |
break; | |
case "-": | |
hasil = input_1 - input_2 | |
break; | |
case "*": | |
hasil = input_1 * input_2 | |
break; | |
case "/": | |
hasil = input_1 / input_2 | |
break; | |
} | |
$(".output").html(`Output: ${hasil}`) | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#hitung").click(function () { | |
var input_1 = $("#input-1").val() | |
var input_2 = $("#input-2").val() | |
input_1 = parseInt(input_1, 10) | |
input_2 = parseInt(input_2, 10) | |
var operator = $("[name=operasi]:checked").val() | |
var hasil = null | |
switch(operator) { | |
case "+": | |
hasil = input_1 + input_2 | |
break; | |
case "-": | |
hasil = input_1 - input_2 | |
break; | |
case "*": | |
hasil = input_1 * input_2 | |
break; | |
case "/": | |
hasil = input_1 / input_2 | |
break; | |
} | |
$(".output").html(`Output: ${hasil}`) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment