-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
57 lines (56 loc) · 1.77 KB
/
script.js
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
let input = document.getElementById('input');
let btn = document.getElementById('add');
let ul = document.getElementById('ul');
let date = new Date();
let hour = date.getHours();
let min = date.getMinutes();
let sec = date.getSeconds();
let am = "Am"
// console.log(time,min,sec);
if(hour > 12){
hour = hour - 12
am = "Pm"
}
if(hour < 10){
hour = "0" + hour
}
if(min < 10){
min = "0" + min
}
if(sec < 10){
sec = "0" + sec
}
function add(){
if(input.value === ""){
Swal.fire({
// title: "The Internet?",
text: "Please fill out",
icon: "error"
});
}
else{
ul.innerHTML += `<li id="li">${input.value} <span>${hour}:${min}:${am}</span> <div class="btn"><i id="btn1" class="fa-solid fa-pen-to-square"></i> <i id="btn2" class="fa-solid fa-trash"></i></div> </li>`
}
input.value = ""
let li = document.getElementById('li')
let btn2 = document.getElementById('btn2')
let btn1 = document.getElementById('btn1');
// let btn3 = document.getElementById('btn3')
btn1.addEventListener('click',function(){
let edit = prompt('Enter your task')
if(edit){
ul.innerHTML = `<li>${edit} <span>${hour}:${min}:${am}</span> <div class="btn"> <i id="btn1" class="fa-solid fa-pen-to-square"></i> <i id="btn2" class="fa-solid fa-trash"></i> </div> </li>`
}
else{
ul.innerHTML = `<li>${edit} <span>${hour}:${min}:${am}</span> <div class="btn"> <i id="btn1" class="fa-solid fa-pen-to-square"></i> <i id="btn2" class="fa-solid fa-trash"></i> </div> </li>`
}
})
btn2.addEventListener('click',function(){
ul.removeChild(ul.lastChild)
})
}
input.addEventListener('keydown',function(event){
if(event.keyCode == "13"){
add()
}
})