Tugas 5 Minggu-6 PWEB Kelas C

Implementasi JQuery: Simple Click Counter


Click counter ini adalah program sederhana hasil implementasi tugas pemrograman web topik "jquery" yang berfungsi sebagai penghitung jumlah klik yang ditampilkan pada layar. Terdapat 2 tombol pada program ini yaitu "count" sebagai pencatat tiap klik dan "reset" untuk mereset jumlah klik. Berikut hasil implementasi programnya:

Kondisi awal program: 



Tombol count diklik:



Tombol reset diklik:


Source code:

<!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>AchFerdi | Tugas 5</title>
    <!-- CSS only -->
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
      crossorigin="anonymous"
    />
  </head>
  <body>
    <div class="container-fluid">
      <center>
        <header>
          <h1>
            <b>Click Counter</b>
          </h1>
        </header>
        <br />
        <div class="content">
          <h2 id="number-count"></h2>
          <button type="button" class="btn btn-primary" id="btn-count">
            count
          </button>
          <button type="button" class="btn btn-secondary" id="btn-reset">
            reset
          </button>
        </div>
      </center>
    </div>

    <!-- JavaScript Bundle with Popper -->
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
      crossorigin="anonymous"
    ></script>

    <!-- jquery bundle -->
    <script
      src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
      integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
      crossorigin="anonymous"
    ></script>

    <!-- My Script -->
    <script>
      $(document).ready(function () {
        // initiate number of count
        let nilai = 0;
        $("#number-count").html(nilai);

        // counting number of click
        $("#btn-count").click(function () {
          $("#number-count").html(nilai++);
        });

        // reset the counter
        $("#btn-reset").click(function () {
          nilai = 0;
          $("#number-count").html(nilai);
        });
      });
    </script>
  </body>
</html>



Link Web: Tugas 5

Link Github: Ferdi761






Comments

Popular posts from this blog

Evolusi Sistem Operasi Android

Kuis Akhir Kelas Evolusi Perangkat Lunak

TUGAS ETS PWEB C