Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Kalkulator</title>
  4. </head>
  5. <body>
  6. <h4>Kalkulator</h4>
  7. <input type=”number” id="one">
  8. <br /><br />
  9. <input type=”number” id="two">
  10. <br /><br />
  11. <input type="number" id="hasil" readonly>
  12. <br /><br />
  13. <button type="submit" id="tambah" onclick="kalkulator('tambah');">+</button>
  14. <button type="submit" id="kurang" onclick="kalkulator('kurang');">-</button>
  15. <button type="submit" id="kali" onclick="kalkulator('kali');">x</button>
  16. <button type="submit" id="bagi" onclick="kalkulator('bagi');">/</button>
  17. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  18. <script type="text/javascript">
  19. function kalkulator(param)
  20. {
  21. var angkaPertama = document.getElementById("one").value;
  22. var angkaKedua = document.getElementById("two").value;
  23. var hasil;
  24.  
  25. if (param == "tambah") {
  26. hasil = (+angkaPertama)+(+angkaKedua);
  27. $("#hasil").val(hasil);
  28. } else if (param == "kurang") {
  29. hasil = angkaPertama-angkaKedua;
  30. $("#hasil").val(hasil);
  31. } else if (param == "kali") {
  32. hasil = angkaPertama*angkaKedua;
  33. $("#hasil").val(hasil);
  34. } else if (param == "bagi") {
  35. hasil = angkaPertama/angkaKedua;
  36. $("#hasil").val(hasil);
  37. } else {
  38. alert("Operasi Tidak Ditemukan");
  39. }
  40. }
  41. </script>
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement