Skip to content

Instantly share code, notes, and snippets.

@imparvez
Created September 22, 2017 07:26
Show Gist options
  • Save imparvez/ac10a0fdda2885e831815fe9b3b8db80 to your computer and use it in GitHub Desktop.
Save imparvez/ac10a0fdda2885e831815fe9b3b8db80 to your computer and use it in GitHub Desktop.
// V5 The For Loop.
// .displayTodos should show .todoText
// .displayTodos should tell you if .todos is empty
// .displayTodos should show .completed
var todoList = {
todos: [],
displayTodos: function(){
if(this.todos.length === 0) { // Chp no: 2 .displayTodos should tell you if .todos is empty
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) { // Chp no: 3 .displayTodos should show .completed
console.log('(x)', this.todos[i].todoText); // Chp no: 1 .displayTodos should show .todoText
} else {
console.log('( )',this.todos[i].todoText); // Chp no: 1 .displayTodos should show .todoText
}
}
}
},
addTodos: function(todoText){
this.todos.push({
todoText: todoText,
completed: false
});
this.displayTodos();
},
changeTodo: function(pos, todoText) {
this.todos[pos].todoText = todoText;
this.displayTodos();
},
deleteTodo: function(pos) {
this.todos.splice(pos, 1);
this.displayTodos();
},
toggleCompleted: function(pos){
var todo = this.todos[pos];
todo.completed = !todo.completed;
this.displayTodos();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment