Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Kalkulator</title>
- </head>
- <body>
- <h4>Kalkulator</h4>
- <input type=”number” id="one">
- <br /><br />
- <input type=”number” id="two">
- <br /><br />
- <input type="number" id="hasil" readonly>
- <br /><br />
- <button type="submit" id="tambah" onclick="kalkulator('tambah');">+</button>
- <button type="submit" id="kurang" onclick="kalkulator('kurang');">-</button>
- <button type="submit" id="kali" onclick="kalkulator('kali');">x</button>
- <button type="submit" id="bagi" onclick="kalkulator('bagi');">/</button>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- <script type="text/javascript">
- function kalkulator(param)
- {
- var angkaPertama = document.getElementById("one").value;
- var angkaKedua = document.getElementById("two").value;
- var hasil;
- if (param == "tambah") {
- hasil = (+angkaPertama)+(+angkaKedua);
- $("#hasil").val(hasil);
- } else if (param == "kurang") {
- hasil = angkaPertama-angkaKedua;
- $("#hasil").val(hasil);
- } else if (param == "kali") {
- hasil = angkaPertama*angkaKedua;
- $("#hasil").val(hasil);
- } else if (param == "bagi") {
- hasil = angkaPertama/angkaKedua;
- $("#hasil").val(hasil);
- } else {
- alert("Operasi Tidak Ditemukan");
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement