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
56 changes: 52 additions & 4 deletions todo_list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
var newTodoList = function() {
// ???
};
var TodoList = function() {
this.tasks = [];
this.counter = 0;
}


TodoList.prototype.add = function(item) {
var task = new Task(item)
task.id = this.counter += 1
return this.tasks.push(task)
}

TodoList.prototype.list = function() {
this.tasks.forEach( function(task) {
console.log(task)
});
}

// ---------------- Task Class ----------------------

var Task = function(item) {
this.id = 0;
this.description = item;
this.completed = false;
}

Task.prototype.complete = function() {
this.completed = true
}

// Driver code

todoList = new TodoList();

todoList.add("bread")
todoList.add("phil")
todoList.add("phil")
todoList.add("phil")
todoList.add("phil")
todoList.add("phil")

// console.log(todoList.tasks)

todoList.list()
var breadTask = todoList.tasks[0]
console.log(breadTask.id) //-> 1 (some unique numerical ID)
console.log(breadTask.description) //-> 'bread'
console.log(breadTask.completed) //-> false


// This should complete the task
breadTask.complete();

breadTask.completed //-> true

todoList.list();


var todoList = newTodoList();