Skip to content

Instantly share code, notes, and snippets.

@abuismaeel
Created September 14, 2017 09:39
Show Gist options
  • Save abuismaeel/c9e3fa8c49a5c6035e205aaf8d994098 to your computer and use it in GitHub Desktop.
Save abuismaeel/c9e3fa8c49a5c6035e205aaf8d994098 to your computer and use it in GitHub Desktop.
Practical JavaScript by Gordan Zhu Todo app.
//created an object TodosList
var TodosList = {
todos: [],//todos array
displayTodos:function() {//method that displays values in array
console.log('My Todos:');
if(this.todos.length===0){//check if it's empty
console.log('Your array is empty.');
}else {//if it's not empty
for(i=0;i<this.todos.length;i++){
//console.log(this.todos[i].todoText);
if(this.todos[i].completed===true){//check if its completed
console.log('( )',this.todos[i].todoText);
}else{
console.log('(x)',this.todos[i].todoText);
}
}
}
},
addTodo: function(todoText) {
this.todos.push({
todoText: todoText,
completed: false
});
this.displayTodos();
},
changeTodo: function(position,todoText){
this.todos[position].todoText= todoText;
this.displayTodos();
},
deleteTodo: function(position){
this.todos[position];
this.displayTodos();
},
toggleCompleted:function(position){
var todo = this.todos[position];
todo.completed = !todo.completed;
this.displayTodos();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment