Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<body>

<input type="button" id="hider" value="Click to hide the text" />
<input type="button" id="hider" value="Klik disini untuk menyembunyikan pesan" />

<div id="text">Text</div>
<div id="text">Teks</div>

<script>
// Here it doesn't matter how we hide the text,
// could also use style.display:
// Disini tidak terlalu penting bagaimana cara menyembunyikan teks,
// bisa juga digunakan style.display
document.getElementById('hider').onclick = function() {
document.getElementById('text').hidden = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<body>

<input type="button" id="hider" value="Click to hide the text" />
<input type="button" id="hider" value="Klik disini untuk menyembunyikan pesan" />

<div id="text">Text</div>
<div id="text">Teks</div>

<script>
/* your code */
/* kode kamu */
</script>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ importance: 5

---

# Hide on click
# Klik untuk menyembunyikan

Add JavaScript to the `button` to make `<div id="text">` disappear when we click it.
Tambah Javascript ke `button` untuk membuat `<div id="text">` hilang pada saat di klik.

The demo:
demo:

[iframe border=1 src="solution" height=80]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Can use `this` in the handler to reference "the element itself" here:
Bisa gunakan `this` pada penangan (_handler_) untuk mereferensi "elemen itu sendiri":

```html run height=50
<input type="button" onclick="this.hidden=true" value="Click to hide">
<input type="button" onclick="this.hidden=true" value="Klik untuk menyembunyikan">
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Hide self
# Sembunyikan diri

Create a button that hides itself on click.
Buat sebuah tombol yang menyembunyikan dirinya sendiri pada saat di klik.

```online
Like this:
<input type="button" onclick="this.hidden=true" value="Click to hide">
Seperti ini:
<input type="button" onclick="this.hidden=true" value="Klik untuk sembunyi">
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
The answer: `1` and `2`.
Jawabannya: `1` dan `2`.

The first handler triggers, because it's not removed by `removeEventListener`. To remove the handler we need to pass exactly the function that was assigned. And in the code a new function is passed, that looks the same, but is still another function.
Pengendali pertama dijalankan, karena tidak di hapuskan oleh `removeEventListener`. Untuk menghapuskan pengendali kita harus meneruskan secara tepat fungsi yang telah di atur. Dan pada kode sebuah fungsi baru di teruskan, terlihat sama, tapi berbeda fungsi.

To remove a function object, we need to store a reference to it, like this:
Untuk menghapuskan objek fungsi, kita harus menyimpan refensi ke fungsi tersebut, seperti ini:

```js
function handler() {
Expand All @@ -13,4 +13,4 @@ button.addEventListener("click", handler);
button.removeEventListener("click", handler);
```

The handler `button.onclick` works independently and in addition to `addEventListener`.
Pengendali `button.onclick` bekerja secara sendiri dan sebagai tambahan untuk `addEvenetListener`.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Which handlers run?
# Pengendali mana yang dijalankan?

There's a button in the variable. There are no handlers on it.
Ada sebuah tombol pada variable. Tidak ada pengedali di tombol tersebut.

Which handlers run on click after the following code? Which alerts show up?
Manakah pengendali yang dijalankan pada saat klik pada kode berikut ini? Manakah `alert` yang akan ditunjukan?

```js no-beautify
button.addEventListener("click", () => alert("1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<body style="height:2000px">

Click on a field to move the ball there.
Klik pada lapangan untuk memindahkan bola kesana.
<br>


Expand All @@ -39,29 +39,29 @@
<script>
field.onclick = function(event) {

// window-relative field coordinates
// Koordinat lapangan relatif terhadap jendela (window)
let fieldCoords = this.getBoundingClientRect();

// the ball has position:absolute, the field: position:relative
// so ball coordinates are relative to the field inner left-upper corner
// bola memiliki position:absolute, lapangan: position:relative
// jadi koordinat bola relatif terhadap sudut dalam kiri atas lapangan
let ballCoords = {
top: event.clientY - fieldCoords.top - field.clientTop - ball.clientHeight / 2,
left: event.clientX - fieldCoords.left - field.clientLeft - ball.clientWidth / 2
};

// prevent crossing the top field boundary
// mencegah melewati batas atas lapangan
if (ballCoords.top < 0) ballCoords.top = 0;

// prevent crossing the left field boundary
// mencegah melewati kiri atas lapangan
if (ballCoords.left < 0) ballCoords.left = 0;


// // prevent crossing the right field boundary
// mencegah melewati batas kanan lapangan
if (ballCoords.left + ball.clientWidth > field.clientWidth) {
ballCoords.left = field.clientWidth - ball.clientWidth;
}

// prevent crossing the bottom field boundary
// mencegah melewati batas bawah lapangan
if (ballCoords.top + ball.clientHeight > field.clientHeight) {
ballCoords.top = field.clientHeight - ball.clientHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
</head>

<body style="height:2000px">

Click on a field to move the ball there.
<br> The ball should never leave the field.
Klik pada lapangan untuk memindahkan bola kesana.
<br> Bola tidak boleh meninggalkan lapangan.


<div id="field">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ importance: 5

---

# Move the ball across the field
# Pindahkan bola ke seberang lapangan

Move the ball across the field to a click. Like this:
Pindahkan bola ke seberang lapangan pada saat di klik. Seperti ini:

[iframe src="solution" height="260" link]

Requirements:
Syarat-Syarat:

- The ball center should come exactly under the pointer on click (if possible without crossing the field edge).
- CSS-animation is welcome.
- The ball must not cross field boundaries.
- When the page is scrolled, nothing should break.
- Pusat bola harus berada tepat dibawah pointer pada saat di klik (jika memungkinkan tanpa melintasi ujung lapangan).
- Animasi CSS jika memungkinkan.
- Bola tidak boleh melintasi batas lapangan.
- Saat halaman di digulir, tidak ada yang rusak.

Notes:
Tambahan:

- The code should also work with different ball and field sizes, not be bound to any fixed values.
- Use properties `event.clientX/event.clientY` for click coordinates.
- Kode harus juga bekerja dengan bola yang berbeda dan berbagai ukuran lapangan, tidak hanya pada ukuran tertentu.
- Gunakan properti `event.clientX/event.clientY` untuk koordinat klik.
Loading