-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTodo-List.html
More file actions
116 lines (101 loc) · 2.4 KB
/
Todo-List.html
File metadata and controls
116 lines (101 loc) · 2.4 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: Arial;
}
.todo-grid,
.todo-input-grid {
display: grid;
grid-template-columns: 200px 150px 100px;
column-gap: 10px;
row-gap: 10px;
align-items: center;
}
.todo-input-grid {
margin-bottom: 10px;
align-items: stretch;
}
.js-name-input,
.js-due-date-input {
font-size: 15px;
padding: 6px;
}
.add-todo-button {
background-color: green;
color: white;
border: none;
font-size: 15px;
cursor: pointer;
}
.delete-todo-button {
background-color: darkred;
color: white;
border: none;
font-size: 15px;
cursor: pointer;
padding-top: 10px;
padding-bottom: 10px;
}
</style>
</head>
<body>
<p>Todo Llist Practice 1</p>
<div class="todo-input-grid">
<input type="text" placeholder="Todo name" class="js-name-input" />
<input type="date" placeholder="Todo date" class="js-due-date-input" />
<button class="add-todo-button" onclick="addTodo()">Add</button>
</div>
<div class="js-todo-list todo-grid"></div>
<script>
const todoList = [
{
name: "make dinner",
dueDate: "2022-12-22",
},
{
name: "wash dishes",
dueDate: "2022-12-23",
},
]
function renderTodoList() {
let todoListHTML = ""
for (let i = 0; i < todoList.length; i++) {
const todoObject = todoList[i]
// const name = todoObject.name
// const dueDate = todoObject.dueDate
const { name, dueDate } = todoObject
const todo = todoList[i]
const html = `
<div>${name}</div>
<div>${dueDate}</div>
<div>
<button
onclick="todoList.splice(${i},1);
renderTodoList();"
class="delete-todo-button">
Delete
</button>
</div>
`
todoListHTML += html
}
console.log(todoListHTML)
document.querySelector(".js-todo-list").innerHTML = todoListHTML
}
function addTodo() {
var inputElement = document.querySelector(".js-name-input")
var name = inputElement.value
var dueDate = document.querySelector(".js-due-date-input").value
todoList.push({ name, dueDate })
console.log(todoList)
inputElement.value = ""
renderTodoList()
}
</script>
</body>
</html>