-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
123 lines (109 loc) · 2.91 KB
/
scripts.js
File metadata and controls
123 lines (109 loc) · 2.91 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
117
118
119
120
121
122
123
// Here is task one:
// Todo List App
// Goal: Simple to-do app with in-memory task storage.
// Each task should have an: id, title, completed
// Features:
// Add task
// Mark task as done/undone
// Filter task according to: completed | pending tasks
// Delete task
// const Task = {
// id: 0,
// title: "",
// completed: false,
// new: function (_title, _id) {
// return {
// id: _id,
// title: _title,
// completed: this.completed,
// };
// },
// };
// const TaskList = [];
// function addTask(_title) {
// const _currentTaskLength = TaskList.length;
// // Create a new task
// //have an id based on itys index
// const _task = Task.new(_title, _currentTaskLength);
// //push it into the list
// TaskList.push(_task);
// //havethe completed is false
// return _currentTaskLength;
// }
// function completeTask(_id) {
// ///ensure id exists
// if (_id > TaskList.length) {
// alert("Task does not exist");
// return;
// }
// if (TaskList[_id].completed == true) {
// alert("Task already completed");
// return;
// }
// if (TaskList[_id].title == "") {
// alert("Task does not exist");
// return;
// }
// //use id to mark the task as completed
// TaskList[_id].completed = true;
// //return id
// }
const Task = {
id: 0,
title: "",
completed: false,
new: function (_title, _id) {
return {
id: _id,
title: _title,
completed: this.completed,
};
},
};
const li = document.createElement("li");
const TaskList = [];
function addTask() {
const _title = document.getElementById("todo-input").value;
if (_title == "") {
alert("Please enter a task");
return;
}
const _currentTaskLength = TaskList.length;
// Create a new task
//have an id based on itys index
const _task = Task.new(_title, _currentTaskLength);
//push it into the list
TaskList.push(_task);
//havethe completed is false
document.getElementById("todo-input").value = "";
updateScreen();
return _currentTaskLength;
}
function updateScreen() {
const TaskLists = document.getElementById("todo-list");
TaskLists.innerHTML = "";
for (let i = 0; i < TaskList.length; i++) {
const li = document.createElement("li");
li.innerHTML = TaskList[i].title;
TaskLists.appendChild(li);
}
return true;
}
function completeTask(_id) {
///ensure id exists
if (_id > TaskList.length) {
alert("Task does not exist");
return;
}
if (TaskList[_id].completed == true) {
alert("Task already completed");
return;
}
if (TaskList[_id].title == "") {
alert("Task does not exist");
return;
}
//use id to mark the task as completed
TaskList[_id].completed = true;
//return id
}