Created
March 17, 2023 13:46
-
-
Save solanoize/0608f4532c4ca5d97babe18ab32296a0 to your computer and use it in GitHub Desktop.
Hitung Progress JS
This file contains hidden or 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 lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <input type="number" placeholder="Target BAB" class="targetBab" /> | |
| <input type="number" placeholder="Progress" class="progress" /> | |
| <button class="cek">Cek Progress</button> | |
| <button class="cetakArray">Cetak Array</button> | |
| <h1 class="hasil"></h1> | |
| <script src="./script.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| let hasil = document.querySelector("h1.hasil"); | |
| let inputTargetBab = document.querySelector(".targetBab"); | |
| let inputProgress = document.querySelector(".progress"); | |
| let btnCek = document.querySelector(".cek"); | |
| let btnCetakArray = document.querySelector(".cetakArray"); | |
| let array1 = []; | |
| function progressTulisan(progress, targetBab) { | |
| return (progress / 100) * targetBab; | |
| } | |
| btnCek.addEventListener("click", function () { | |
| let nilaiTargetBab = parseInt(inputTargetBab.value); | |
| let nilaiProgress = parseInt(inputProgress.value); | |
| let hasilHitungan = progressTulisan(nilaiProgress, nilaiTargetBab); | |
| let obj = { | |
| nama: "", | |
| targetBab: nilaiTargetBab, | |
| progress: nilaiProgress, | |
| selesai: hasilHitungan, | |
| belum: nilaiTargetBab - hasilHitungan, | |
| }; | |
| array1.push(obj); | |
| inputTargetBab.value = 0; | |
| inputProgress.value = 0; | |
| }); | |
| btnCetakArray.addEventListener("click", function () { | |
| console.log(array1); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment