-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript.js
More file actions
63 lines (59 loc) · 1.57 KB
/
JavaScript.js
File metadata and controls
63 lines (59 loc) · 1.57 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
import { equal } from "assert";
var todoList = {
todos: [],
displayTodos: function() {
if (this.todos.length === 0) {
console.log("Your todo list is empty!");
} else {
console.log("My Todos:");
for (var i = 0; i < this.todos.length; i++) {
if (this.todos[i].completed === true) {
console.log("(x)", this.todos[i].todoText);
} else {
console.log("()", this.todos[i].todoText);
}
}
}
},
addTodo: function(todoText) {
this.todos.push({
todoText: todoText,
completed: false //Boolean Value
});
},
changeTodo: function(position, todoText) {
//this.todos[position] = newValue;
this.todos[position].todoText = todoText;
this.displayTodos();
},
deleteTodo: function(position) {
this.todos.splice(position, 1);
this.displayTodos();
},
toggleCompleted: function(position) {
var todo = this.todos[position];
todo.completed = !todo.completed;
this.displayTodos();
},
toggleAll: function() {
var totalTodos = this.todos.length;
var completedTodos = 0;
//Get number of completed todos
for (var i = 0; i < totalTodos; i++) {
if (this.todos[i].completed === true) {
completedTodos++;
}
}
//If everything's true, make everything false
if (completedTodos === totalTodos) {
for (var i = 0; i < totalTodos; i++) {
this.todos[i].completed = false;
}
} else {
for (var i = 0; i < totalTodos; i++) {
this.this.todo[i].completed = true;
}
}
this.displayTodos();
}
};