-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
52 lines (41 loc) · 1.46 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
let todoList = [];
check();
function add(){
let inputElement = document.querySelector('.todo-input');
let inputText = inputElement.value;
let dateElement = document.querySelector('.todo-date');
let inputDate = dateElement.value;
let timeElement = document.querySelector('.todo-time');
let inputTime = timeElement.value;
let spanElement = document.querySelector('span');
todoList.push({item : inputText , dueDate : inputDate , dueTime : inputTime});
inputElement.value= '';
dateElement.value = "";
timeElement.value = "";
spanElement.innerHTML= '' ;
display()
}
function display(){
let containerElement = document.querySelector('.show-container');
let newHTMl = '';
for(let i =0 ;i<todoList.length;i++){
let {item,dueDate,dueTime} = todoList[i];
newHTMl+= `
<span>${item}</span>
<span>${dueDate}</span>
<span>${dueTime}</span>
<button class = "btn-del btn" onclick = "todoList.splice(${i},1); display(); check();">Delete</button>
`
}
containerElement.innerHTML = newHTMl;
}
function check(){
if(todoList.length == 0){
let spanElement = document.querySelector('span');
newHTMl =`
<img src="images/No-Tasks.gif" alt="No-Tasks">
<p class = "no-tasks-heading" >No Tasks to do...</p>
`
document.querySelector('span').innerHTML = newHTMl;
}
}