Skip to content

Commit 372d95b

Browse files
committed
translate modifying the document
1 parent e594d67 commit 372d95b

33 files changed

Lines changed: 849 additions & 813 deletions

File tree

2-ui/1-document/07-modifying-document/1-createtextnode-vs-innerhtml/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
Answer: **1 and 3**.
1+
Jawabannya: **1 dan 3**.
22

3-
Both commands result in adding the `text` "as text" into the `elem`.
3+
Kedua perintah tersebut mengakibatkan penambahan `text` 'sebagai teks' ke dalam `elem`
44

5-
Here's an example:
5+
Berikut adalah contohnya:
66

77
```html run height=80
88
<div id="elem1"></div>
99
<div id="elem2"></div>
1010
<div id="elem3"></div>
1111
<script>
12-
let text = '<b>text</b>';
12+
let text = "<b>text</b>";
1313
1414
elem1.append(document.createTextNode(text));
1515
elem2.innerHTML = text;

2-ui/1-document/07-modifying-document/1-createtextnode-vs-innerhtml/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 5
1+
Tingkat kepentingan: 5
22

33
---
44

55
# createTextNode vs innerHTML vs textContent
66

7-
We have an empty DOM element `elem` and a string `text`.
7+
Kita memiliki elemen DOM kosong `elem` dan sebuah string `text`.
88

9-
Which of these 3 commands will do exactly the same?
9+
Di antara 3 perintah ini, mana yang akan melakukan hal yang sama?
1010

1111
1. `elem.append(document.createTextNode(text))`
1212
2. `elem.innerHTML = text`

2-ui/1-document/07-modifying-document/10-clock-setinterval/solution.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
First, let's make HTML/CSS.
1+
Pertama, mari membuat HTML/CSS.
22

3-
Each component of the time would look great in its own `<span>`:
3+
Setiap komponen waktu akan terlihat bagus dalam elemen `<span>` sendiri:
44

55
```html
66
<div id="clock">
7-
<span class="hour">hh</span>:<span class="min">mm</span>:<span class="sec">ss</span>
7+
<span class="hour">hh</span>:<span class="min">mm</span>:<span class="sec"
8+
>ss</span
9+
>
810
</div>
911
```
1012

11-
Also we'll need CSS to color them.
13+
Kita juga akan membutuhkan CSS untuk memberi warna pada mereka.
1214

13-
The `update` function will refresh the clock, to be called by `setInterval` every second:
15+
Fungsi `update` akan menyegarkan jam, dipanggil oleh `setInterval` setiap detik:
1416

1517
```js
1618
function update() {
@@ -32,15 +34,17 @@ function update() {
3234
}
3335
```
3436

35-
In the line `(*)` we every time check the current date. The calls to `setInterval` are not reliable: they may happen with delays.
37+
Pada baris `(*)`, kita memeriksa tanggal saat ini setiap kali. Panggilan ke `setInterval` tidak dapat diandalkan: mereka mungkin terjadi dengan penundaan.
3638

37-
The clock-managing functions:
39+
Fungsi pengelolaan jam:
3840

3941
```js
4042
let timerId;
4143

42-
function clockStart() { // run the clock
43-
if (!timerId) { // only set a new interval if the clock is not running
44+
function clockStart() {
45+
// menjalankan jam
46+
if (!timerId) {
47+
// hanya atur interval baru jika jam tidak berjalan
4448
timerId = setInterval(update, 1000);
4549
}
4650
update(); // (*)
@@ -52,6 +56,6 @@ function clockStop() {
5256
}
5357
```
5458

55-
Please note that the call to `update()` is not only scheduled in `clockStart()`, but immediately run in the line `(*)`. Otherwise the visitor would have to wait till the first execution of `setInterval`. And the clock would be empty till then.
59+
Harap dicatat bahwa panggilan ke `update()` tidak hanya dijadwalkan dalam `clockStart()`, tetapi segera dijalankan pada baris `(*)`. Jika tidak, pengunjung harus menunggu sampai eksekusi pertama `setInterval`. Dan jam akan kosong sampai saat itu.
5660

57-
Also it is important to set a new interval in `clockStart()` only when the clock is not running. Otherways clicking the start button several times would set multiple concurrent intervals. Even worse - we would only keep the `timerID` of the last interval, losing references to all others. Then we wouldn't be able to stop the clock ever again! Note that we need to clear the `timerID` when the clock is stopped in the line `(**)`, so that it can be started again by running `clockStart()`.
61+
Juga penting untuk mengatur interval baru dalam `clockStart()` hanya ketika jam tidak berjalan. Jika tidak, mengklik tombol start beberapa kali akan mengatur beberapa interval yang berjalan bersamaan. Lebih buruk lagi - kita hanya akan menyimpan `timerID` dari interval terakhir, kehilangan referensi ke semua yang lain. Maka kita tidak akan bisa menghentikan jam lagi! Perlu dicatat bahwa kita perlu membersihkan `timerID` ketika jam berhenti pada baris `(**)`, sehingga itu dapat dimulai kembali dengan menjalankan `clockStart()`.
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
<!DOCTYPE HTML>
1+
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<style>
5-
.hour {
6-
color: red
7-
}
8-
9-
.min {
10-
color: green
11-
}
12-
13-
.sec {
14-
color: blue
15-
}
16-
</style>
17-
</head>
3+
<head>
4+
<style>
5+
.hour {
6+
color: red;
7+
}
188

19-
<body>
9+
.min {
10+
color: green;
11+
}
2012

21-
<div id="clock">
22-
<span class="hour">hh</span>:<span class="min">mm</span>:<span class="sec">ss</span>
23-
</div>
13+
.sec {
14+
color: blue;
15+
}
16+
</style>
17+
</head>
2418

25-
<script>
26-
let timerId;
19+
<body>
20+
<div id="clock">
21+
<span class="hour">hh</span>:<span class="min">mm</span>:<span class="sec"
22+
>ss</span
23+
>
24+
</div>
2725

28-
function update() {
29-
let clock = document.getElementById('clock');
30-
let date = new Date();
26+
<script>
27+
let timerId;
3128

32-
let hours = date.getHours();
33-
if (hours < 10) hours = '0' + hours;
34-
clock.children[0].innerHTML = hours;
29+
function update() {
30+
let clock = document.getElementById("clock");
31+
let date = new Date();
3532

36-
let minutes = date.getMinutes();
37-
if (minutes < 10) minutes = '0' + minutes;
38-
clock.children[1].innerHTML = minutes;
33+
let hours = date.getHours();
34+
if (hours < 10) hours = "0" + hours;
35+
clock.children[0].innerHTML = hours;
3936

40-
let seconds = date.getSeconds();
41-
if (seconds < 10) seconds = '0' + seconds;
42-
clock.children[2].innerHTML = seconds;
43-
}
37+
let minutes = date.getMinutes();
38+
if (minutes < 10) minutes = "0" + minutes;
39+
clock.children[1].innerHTML = minutes;
4440

45-
function clockStart() {
46-
// set a new interval only if the clock is stopped
47-
// otherwise we would rewrite the timerID reference to the running interval and wouldn't be able to stop the clock ever again
48-
if (!timerId) {
49-
timerId = setInterval(update, 1000);
41+
let seconds = date.getSeconds();
42+
if (seconds < 10) seconds = "0" + seconds;
43+
clock.children[2].innerHTML = seconds;
5044
}
51-
update(); // <-- start right now, don't wait 1 second till the first setInterval works
52-
}
5345

54-
function clockStop() {
55-
clearInterval(timerId);
56-
timerId = null; // <-- clear timerID to indicate that the clock has been stopped, so that it is possible to start it again in clockStart()
57-
}
46+
function clockStart() {
47+
// atur interval baru hanya jika jam berhenti
48+
// jika tidak, kita akan menulis kembali referensi timerID ke interval yang berjalan dan tidak akan dapat menghentikan jam lagi
49+
if (!timerId) {
50+
timerId = setInterval(update, 1000);
51+
}
52+
update(); // <-- mulai sekarang juga, jangan tunggu 1 detik sampai setInterval pertama berfungsi
53+
}
5854

59-
clockStart();
60-
</script>
55+
function clockStop() {
56+
clearInterval(timerId);
57+
timerId = null; // <-- hapus timerID untuk menunjukkan bahwa jam telah dihentikan, sehingga memungkinkan untuk memulainya kembali di clockStart()
58+
}
6159

62-
<!-- click on this button calls clockStart() -->
63-
<input type="button" onclick="clockStart()" value="Start">
60+
clockStart();
61+
</script>
6462

65-
<!-- click on this button calls clockStop() -->
66-
<input type="button" onclick="clockStop()" value="Stop">
63+
<!-- tekan tombol ini untuk memanggil clockStart() -->
64+
<input type="button" onclick="clockStart()" value="Start" />
6765

68-
</body>
66+
<!-- tekan tombol ini untuk memanggil clockStop() -->
67+
<input type="button" onclick="clockStop()" value="Stop" />
68+
</body>
6969
</html>
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<!DOCTYPE HTML>
1+
<!DOCTYPE html>
22
<html>
3-
<body>
3+
<body>
4+
<!-- tekan tombol ini untuk memanggil clockStart() -->
5+
<input type="button" onclick="clockStart()" value="Start" />
46

5-
<!-- click on this button calls clockStart() -->
6-
<input type="button" onclick="clockStart()" value="Start">
7-
8-
<!-- click on this button calls clockStop() -->
9-
<input type="button" onclick="clockStop()" value="Stop">
10-
11-
</body>
7+
<!-- tekan tombol ini untuk memanggil clockStop() -->
8+
<input type="button" onclick="clockStop()" value="Stop" />
9+
</body>
1210
</html>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
importance: 4
1+
Tingkat kepentingan: 4
22

33
---
44

5-
# Colored clock with setInterval
5+
# Jam Berwarna dengan setInterval
66

7-
Create a colored clock like here:
7+
Buatlah jam berwarna seperti di sini:
88

99
[iframe src="solution" height=60]
1010

11-
Use HTML/CSS for the styling, JavaScript only updates time in elements.
11+
Gunakan HTML/CSS untuk styling, JavaScript hanya untuk memperbarui waktu pada elemen-elemen.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
Ketika kita perlu menyisipkan sebagian HTML di suatu tempat, `insertAdjacentHTML` adalah pilihan terbaik.
12

2-
When we need to insert a piece of HTML somewhere, `insertAdjacentHTML` is the best fit.
3-
4-
The solution:
3+
Solusi:
54

65
```js
7-
one.insertAdjacentHTML('afterend', '<li>2</li><li>3</li>');
6+
one.insertAdjacentHTML("afterend", "<li>2</li><li>3</li>");
87
```
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
importance: 5
1+
Tingkat kepentingan: 5
22

33
---
44

5-
# Insert the HTML in the list
5+
# Menyisipkan HTML ke dalam daftar
66

7-
Write the code to insert `<li>2</li><li>3</li>` between two `<li>` here:
7+
Tulis kode untuk menyisipkan `<li>2</li><li>3</li>` antara dua `<li>` di sini:
88

99
```html
1010
<ul id="ul">
1111
<li id="one">1</li>
12+
<!-- Menyisipkan `<li>2</li><li>3</li>` di sini -->
1213
<li id="two">4</li>
1314
</ul>
1415
```
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
The solution is short, yet may look a bit tricky, so here I provide it with extensive comments:
1+
Solusinya singkat, namun mungkin terlihat sedikit rumit, jadi di sini saya berikan dengan komentar yang ekstensif:
22

33
```js
44
let sortedRows = Array.from(table.tBodies[0].rows) // 1
5-
.sort((rowA, rowB) => rowA.cells[0].innerHTML.localeCompare(rowB.cells[0].innerHTML));
5+
.sort((rowA, rowB) =>
6+
rowA.cells[0].innerHTML.localeCompare(rowB.cells[0].innerHTML)
7+
);
68

79
table.tBodies[0].append(...sortedRows); // (3)
810
```
911

10-
The step-by-step algorthm:
12+
Algoritma langkah-demi-langkah:
1113

12-
1. Get all `<tr>`, from `<tbody>`.
13-
2. Then sort them comparing by the content of the first `<td>` (the name field).
14-
3. Now insert nodes in the right order by `.append(...sortedRows)`.
14+
1. Dapatkan semua `<tr>`, dari `<tbody>`.
15+
2. Kemudian urutkan mereka dengan membandingkan berdasarkan konten `<td>` pertama (bidang nama).
16+
3. Sekarang masukkan node dengan urutan yang benar dengan `.append(...sortedRows)`.
1517

16-
We don't have to remove row elements, just "re-insert", they leave the old place automatically.
18+
Kita tidak perlu menghapus elemen baris, cukup "memasukkan kembali", karena mereka akan meninggalkan tempat lama secara otomatis.
1719

18-
P.S. In our case, there's an explicit `<tbody>` in the table, but even if HTML table doesn't have `<tbody>`, the DOM structure always has it.
20+
P.S. Dalam kasus kita, ada <tbody> yang eksplisit dalam tabel, tetapi bahkan jika tabel HTML tidak memiliki <tbody>, struktur DOM selalu memiliki elemen tersebut.
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
<!DOCTYPE html>
22

33
<table id="table">
4-
<thead>
5-
<tr>
6-
<th>Name</th><th>Surname</th><th>Age</th>
7-
</tr>
8-
</thead>
9-
<tbody>
10-
<tr>
11-
<td>John</td><td>Smith</td><td>10</td>
12-
</tr>
13-
<tr>
14-
<td>Pete</td><td>Brown</td><td>15</td>
15-
</tr>
16-
<tr>
17-
<td>Ann</td><td>Lee</td><td>5</td>
18-
</tr>
19-
<tr>
20-
<td>...</td><td>...</td><td>...</td>
21-
</tr>
22-
</tbody>
4+
<thead>
5+
<tr>
6+
<th>Nama</th>
7+
<th>Nama Belakang</th>
8+
<th>Umur</th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
<tr>
13+
<td>John</td>
14+
<td>Smith</td>
15+
<td>10</td>
16+
</tr>
17+
<tr>
18+
<td>Pete</td>
19+
<td>Brown</td>
20+
<td>15</td>
21+
</tr>
22+
<tr>
23+
<td>Ann</td>
24+
<td>Lee</td>
25+
<td>5</td>
26+
</tr>
27+
<tr>
28+
<td>...</td>
29+
<td>...</td>
30+
<td>...</td>
31+
</tr>
32+
</tbody>
2333
</table>
2434

2535
<script>
26-
let sortedRows = Array.from(table.tBodies[0].rows)
27-
.sort((rowA, rowB) => rowA.cells[0].innerHTML.localeCompare(rowB.cells[0].innerHTML));
36+
let sortedRows = Array.from(table.tBodies[0].rows).sort((rowA, rowB) =>
37+
rowA.cells[0].innerHTML.localeCompare(rowB.cells[0].innerHTML)
38+
);
2839

2940
table.tBodies[0].append(...sortedRows);
3041
</script>

0 commit comments

Comments
 (0)