Closed odv closed 4 years ago
let toDoApp = {
todos: [],
displayTodos: function() {
if (this.todos.length == 0) {
return 'My todos list is empty';
} else {
for (let i=0; i < this.todos.length; i++){
console.log(this.todos[i].completed == true ? `(x) ${this.todos[i].todoText}` : `() ${this.todos[i].todoText}`);
}
}
},
addTodos: function(input) {
this.todos.push({
todoText: input,
completed: false
});
this.displayTodos();
},
changeTodos: function(output, position) {
this.todos[position].todoText = output;
this.displayTodos();
},
toggleCompleted: function(pos) {
this.todos[pos].completed = !this.todos[pos].completed;
this.displayTodos();
},
toggleAll: function(){
let taskNo = this.todos.length;
let completedTasks = 0;
for (let i=0; i<taskNo; i++) {
if (this.todos[i].completed == true) {
completedTasks += 1;
}
};
for (let i=0; i<taskNo; i++) {
if (completedTasks == taskNo) {
this.todos[i].completed = false;
} else {
this.todos[i].completed = true;
}
}
this.displayTodos();
},
deleteTodos: function(element) {
this.todos.splice(element, 1);
this.displayTodos();
},
deleteAllTodos: function() {
this.todos = [];
this.displayTodos();
}
};