-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
113 lines (108 loc) · 3.02 KB
/
Copy pathapp.js
File metadata and controls
113 lines (108 loc) · 3.02 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
let idCount = 0;
let todos = []
let enter = document.getElementById('input');
enter.addEventListener('keydown', (event) => {
if (event.key == 'Enter') {
addTodo()
}
})
function addTodo() {
let input = document.getElementById('input');
if (input.value.trim() === ''){
Swal.fire({
title: "Todo empty!",
text: "Todo cannot be empty!",
icon: "error"
});
}
else{
todos.push({
id: idCount,
name: input.value
})
input.value = "";
render()
}
}
function render() {
let input = document.getElementById('input').value;
input = ''
let todo = document.getElementById('todos');
todo.style.height = '40vh'
todo.innerHTML = ""
for (let i = 0; i < todos.length; i++) {
console.log(todos[i])
let todo_Div = document.createElement('div');
let todo_p = document.createElement('p');
let deletBtn = document.createElement('button');
let updateBtn = document.createElement('button');
let time = document.createElement('strong')
todo_p.textContent = todos[i].name;
let date = new Date();
let hours = date.getHours();
let minuts = date.getMinutes();
let second = date.getSeconds();
let am_pm = 'AM'
if (hours > 12){
hours = hours - 12;
am_pm = 'PM'
};
let total = `${hours.toString().padStart(2, 0)}:${minuts.toString().padStart(2,0)}:${second.toString().padStart(2,0)}`
// console.log(total)
time.textContent = total
// time.textContent = total
// time.innerHTML = setInterval(clock,1000)
deletBtn.innerHTML = '<i class="fa-solid fa-trash"></i>';
updateBtn.innerHTML = '<i class="fa-solid fa-pen-to-square"></i>';
todo_Div.setAttribute('id', todos[i].id);
todo_Div.setAttribute('class', 'todoList');
todo_p.setAttribute('id', 'para')
deletBtn.setAttribute('onclick', `deletTodo(${todos[i].id})`)
updateBtn.setAttribute('onclick', `editBtn(${todos[i].id})`)
todo_Div.appendChild(todo_p);
todo_Div.appendChild(deletBtn);
todo_Div.appendChild(updateBtn);
todo_Div.appendChild(time)
todo.appendChild(todo_Div);
console.log(todo)
}
idCount++
}
function deletTodo(del) {
let index;
for (let i = 0; i < todos.length; i++) {
if (todos[i].id == del) {
index = i
// break;
}
}
console.log('index',index)
todos.splice(index , 1);
render()
// if (index !== -1){
// }
}
function editBtn(end) {
console.log(end)
let index;
for (let i = 0; i < todos.length; i++) {
if(todos[i].id == end){
index = i
}
}
let user = prompt('Enter your todo',todos[index].name);
if(user.trim() !== ''){
todos[index].name = user;
render()
}
else{
Swal.fire({
title: "Todo empty!",
text: "Todo cannot be empty!",
icon: "error"
});
// alert("Todo name cannot be empty!");
}
}
function clock(){
}