-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
88 lines (80 loc) · 2.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!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>Challenge - DOM</title>
<style>
body {
margin: 0;
padding: 0;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
#app {
width: 800px;
height: 400px;
background-color: aliceblue;
box-shadow: 5px 5px 10px 5px rgba(0, 0, 0, 0.2);
border-radius: 10px;
margin: 50px auto;
padding: 20px;
}
#todo-title {
padding: 5px 5px;
background-color: antiquewhite;
text-align: center;
}
h3 {
text-align: center;
}
#todo-input {
height: 40px;
width: 100%;
}
</style>
</head>
<body>
<div id="app">
<!-- TODO: Buatlah sebuah header dengan id todo-title -->
<!-- TODO: Buatlah sebuah subtitle dengan id todo-subtitle -->
<div id="todo-title"><h2>To-Do List</h2></div>
<h3 id="todo-subtitle">- Today I Need To -</h3>
<!-- Section: input -->
<!-- TODO: Buatlah sebuah input bertipe text dengan id todo-input -->
<!-- TODO: Buatlah sebuah button dengan id todo-submit -->
<input type="text" id="todo-input" />
<button type="submit" id="todo-submit">submit</button>
<!-- Section output -->
<!-- TODO: Buatlah sebuah <ul> dengan id todo-output -->
<ul id="todo-output"></ul>
</div>
<!-- ! Untuk tantangan ini, script jangan diubah ke external js yah ! -->
<script>
// TODO: Deklarasi variable sesuai dengan kebutuhan di sini
let button = document.getElementById("todo-submit");
let input = document.getElementById("todo-input");
let output = document.getElementById("todo-output");
// TODO: Buatlah sebuah fungsi dengan nama fnClickHandler
// Fungsi yang digunakan untuk menambahkan tulisan
// Jangan ubah cara deklarasi fungsinya, cukup isi saja
function fnClickHandler(toDoItem) {
let li = document.createElement("li");
li.innerHTML = toDoItem;
output.appendChild(li);
}
// TODO: register event onclick / addEventListener untuk button
// akan menjalankan fungsi fnClickHandler
button.addEventListener("click", function () {
return fnClickHandler(input.value);
});
// TODO: register event onkeypress / addEventListener untuk input
// sehingga saat di input ditekan enter akan menjalankan fungsi fnClickHandler juga
document.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
return fnClickHandler(input.value);
}
});
</script>
</body>
</html>