-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3-7.app.js
More file actions
45 lines (35 loc) · 971 Bytes
/
3-7.app.js
File metadata and controls
45 lines (35 loc) · 971 Bytes
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
var todoList = [];
var makeTodo = function (task) {
var onclickHandler = 'removeTodo (' + JSON.stringify (task) + ')';
return lith.g ([
['p', task],
['button', {onclick: onclickHandler}, 'Mark as complete']
]);
}
var placeTodos = function () {
var allTodos = '';
todoList.map (function (task) {
allTodos = allTodos + makeTodo (task);
});
document.getElementById ('todos').innerHTML = allTodos;
}
var addTodo = function () {
var todo = prompt ('What do you want to do?');
todoList.push (todo);
placeTodos ();
saveTodos ();
}
var removeTodo = function (task) {
todoList.splice (todoList.indexOf (task), 1);
placeTodos ();
saveTodos ();
}
var loadTodos = function () {
var loadedTodos = localStorage.getItem ('todos');
if (loadedTodos) todoList = JSON.parse (loadedTodos);
}
var saveTodos = function () {
localStorage.setItem ('todos', JSON.stringify (todoList));
}
loadTodos ();
placeTodos ();