Created
September 20, 2017 17:13
-
-
Save imparvez/7805d08fa9243f8b0f91536b921b5209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// V4 Boolean. | |
// todoList.addTodo should add object. | |
// todoList.changeTodo should change the todoText property. | |
// todoList.toggleCompleted should change the completed property. | |
var todoList = { | |
todos: [], // 1. It should store the todos arrays on an object | |
displayTodos: function(){ | |
console.log('My Todos: ', this.todos) | |
}, | |
addTodos: function(todoText){ // Chp no: 1 todoList.addTodo should add object. | |
this.todos.push({ // addTodos will push an object rather then a single string | |
todoText: todoText, // Our Todo | |
completed: false // Status saying by default it is yet to be completed | |
}); | |
this.displayTodos(); | |
}, | |
changeTodo: function(pos, todoText) { // Chp no: 2 todoList.changeTodo should change the todoText property. | |
this.todos[pos].todoText = todoText; | |
this.displayTodos(); | |
}, | |
deleteTodo: function(pos) { | |
this.todos.splice(pos, 1); | |
this.displayTodos(); | |
}, | |
toggleCompleted: function(pos){ // Chp no: 3 todoList.toggleCompleted should change the completed property. | |
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