From dd187335379bb405cc3cd4e3839516e4732f63d3 Mon Sep 17 00:00:00 2001 From: Emilio Corpus & Andres Castillo Date: Mon, 3 Aug 2015 17:14:41 -0700 Subject: [PATCH] Complete challenge --- todo_list.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/todo_list.js b/todo_list.js index 110fce6..becf3e5 100644 --- a/todo_list.js +++ b/todo_list.js @@ -1,10 +1,79 @@ -var newTodoList = function() { - // ??? +var TodoList = function() { + this.id = 1 + this.tasks = [], + this.add = function(description) { + this.tasks.push(new Task(description, this.id)) + this.id +=1 + }, + this.list = function() { + for(var i=0 ; i [Task, Task, Task] + +// groceryList.list(); +//> Task {id: 1, description: 'bread', completed: false} +//> Task {id: 2, description: 'cheese', completed: false} +//> Task {id: 3, description: 'milk', completed: false} + + + // getting a task object +var breadTask = groceryList.tasks[0]; + +console.log(breadTask) + +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 + +groceryList.list(); +//> Task {id: 1, description: 'bread', completed: true} +//> Task {id: 2, description: 'cheese', completed: false} +//> Task {id: 3, description: 'milk', completed: false} + + +// This should remove the task from the todo list +groceryList.remove(breadTask); + +groceryList.add(breadTask); + +groceryList.list(); +// > Task {id: 2, description: 'cheese', completed: false} +// > Task {id: 3, description: 'milk', completed: false} -var todoList = newTodoList(); \ No newline at end of file