Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions todo_list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
var newTodoList = function() {
// ???
var TodoList = function() {
var Task = function(item){
this.id = 0,
this.description = item,
this.completed = false
}

Task.prototype.complete = function(){
this.completed = true
}
this.tasks = []
this.add = function(item){
var newTask = new Task(item);
this.tasks.push(newTask)
}

this.list = function(){
for(var x in this.tasks){
console.log(this.tasks[x])}
}

this.get = function(indx){
console.log(this.tasks[indx])
}

this.remove = function(item){

var remove_it = this.tasks.indexOf(item)
this.tasks.splice(remove_it, 1);

}
};



// Driver code


var todoList = newTodoList();
var todoList = new TodoList();

todoList.add("Bread")
todoList.add("cheese")
todoList.add("Milk")
// todoList.list()
// console.log(" ")
// todoList.get(1)

var breadTask = todoList.tasks[0]
// breadTask.id
// breadTask.description
// breadTask.completed

// breadTask.complete()
// breadTask.completed
todoList.remove(breadTask)
todoList.list()