From 6ce7518f31dc0951070b662d6149da5c5d0edf20 Mon Sep 17 00:00:00 2001 From: Lauryn Amanda Porte & Chris Date: Mon, 13 Jul 2015 12:24:12 -0700 Subject: [PATCH 1/3] Add add --- todo_list.js | 30 +++++++++++++++--- todo_list_old.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 todo_list_old.js diff --git a/todo_list.js b/todo_list.js index 110fce6..7ca308c 100644 --- a/todo_list.js +++ b/todo_list.js @@ -1,10 +1,32 @@ -var newTodoList = function() { - // ??? +// function ToDoList() { +// this.tasks = [] +// } + +function Task(task) { + this.task = task, + this.complete = false +} + +function ToDoList() { + this.tasks = []; +}; + +ToDoList.prototype.add = function(task) { + var newTask = new Task(task); + this.tasks.push(newTask); }; +ToDoList.prototype.list = function() { + for (i=0; i < this.tasks.length; i++) { + console.log(this.tasks[i]); + } +}; -// Driver code +fooList = new ToDoList(); +fooList.add('sweet stuff'); +fooList.add('foo foo'); + +// Driver code -var todoList = newTodoList(); \ No newline at end of file diff --git a/todo_list_old.js b/todo_list_old.js new file mode 100644 index 0000000..b0c19fa --- /dev/null +++ b/todo_list_old.js @@ -0,0 +1,79 @@ +// PS: +// add > add a new task to the array +// tasks > return the array of tasks +// list > console.log each task +// indexOf function, takes a task as input and returns the index +// remove, takes a task as input and deletes it from the array + +function Task(task) { + this.task = task, + this.completed = false +} + +var createTodoList = function() { + var todoList = { + tasks: [], + add: function(task) { + var newTask = new Task(task); + this.tasks.push(newTask); + }, + list: function() { + console.log(this.tasks); + }, + indexOf: function(task) { + return this.tasks.indexOf(task) + }, + remove: function(index) { + delete this.tasks[index]; + }, + get: function(index) { + return this.tasks[index] + }, + complete: function(index) { + this.tasks[index].complete = true; + } + }; + return todoList; +}; + + +// Driver code + + +// Release 1 + +var groceryList = createTodoList(); +groceryList.add('bread'); +groceryList.add('cheese'); +groceryList.add('milk'); +groceryList.list(); //-> ['bread', 'cheese', 'milk'] +groceryList.indexOf('cheese'); //-> 1 +groceryList.remove(1); +groceryList.list(); //-> ['bread', 'milk'] + +// release 2 + + + +var groceryList = createTodoList(); +groceryList.add('bread'); +groceryList.add('cheese'); +groceryList.add('milk'); +groceryList.list(); //-> [ +// {description: 'bread', completed: false}, +// {description: 'cheese', completed: false}, +// {description: 'milk', completed: false}, +// ]; +groceryList.indexOf('cheese'); //-> 1 +groceryList.get(1); //-> {description: 'cheese', completed: false} +groceryList.complete(1); +groceryList.list(); //-> [ +// {description: 'bread', completed: false}, +// {description: 'cheese', completed: true}, +// {description: 'milk', completed: false}, +// ]; +groceryList.remove(1); +groceryList.list(); //-> [ +// {description: 'bread', completed: false}, +// {description: 'milk', completed: false}, +// ]; From 1d82281fd16cdfbe79d4749a1910e0e9d4b3c00b Mon Sep 17 00:00:00 2001 From: Lauryn Amanda Porte & Chris Date: Mon, 13 Jul 2015 12:34:21 -0700 Subject: [PATCH 2/3] fooListgit add .git add . --- todo_list.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/todo_list.js b/todo_list.js index 7ca308c..52462a6 100644 --- a/todo_list.js +++ b/todo_list.js @@ -11,9 +11,12 @@ function ToDoList() { this.tasks = []; }; + ToDoList.prototype.add = function(task) { var newTask = new Task(task); this.tasks.push(newTask); + var index = this.tasks.indexOf(newTask); + this.tasks[index].id = index + 1 }; ToDoList.prototype.list = function() { From 72f9f2259d65c70cf7f5000682ba5c658468187e Mon Sep 17 00:00:00 2001 From: Lauryn Amanda Porte & Chris Date: Mon, 13 Jul 2015 14:06:34 -0700 Subject: [PATCH 3/3] Add completed method --- todo_list.js | 7 ++++- todo_list_old.js | 79 ------------------------------------------------ 2 files changed, 6 insertions(+), 80 deletions(-) delete mode 100644 todo_list_old.js diff --git a/todo_list.js b/todo_list.js index 52462a6..23de106 100644 --- a/todo_list.js +++ b/todo_list.js @@ -4,7 +4,12 @@ function Task(task) { this.task = task, - this.complete = false + this.completed = false, + this.description = 'buy ' + task +}; + +Task.prototype.complete = function() { + this.completed = true; } function ToDoList() { diff --git a/todo_list_old.js b/todo_list_old.js deleted file mode 100644 index b0c19fa..0000000 --- a/todo_list_old.js +++ /dev/null @@ -1,79 +0,0 @@ -// PS: -// add > add a new task to the array -// tasks > return the array of tasks -// list > console.log each task -// indexOf function, takes a task as input and returns the index -// remove, takes a task as input and deletes it from the array - -function Task(task) { - this.task = task, - this.completed = false -} - -var createTodoList = function() { - var todoList = { - tasks: [], - add: function(task) { - var newTask = new Task(task); - this.tasks.push(newTask); - }, - list: function() { - console.log(this.tasks); - }, - indexOf: function(task) { - return this.tasks.indexOf(task) - }, - remove: function(index) { - delete this.tasks[index]; - }, - get: function(index) { - return this.tasks[index] - }, - complete: function(index) { - this.tasks[index].complete = true; - } - }; - return todoList; -}; - - -// Driver code - - -// Release 1 - -var groceryList = createTodoList(); -groceryList.add('bread'); -groceryList.add('cheese'); -groceryList.add('milk'); -groceryList.list(); //-> ['bread', 'cheese', 'milk'] -groceryList.indexOf('cheese'); //-> 1 -groceryList.remove(1); -groceryList.list(); //-> ['bread', 'milk'] - -// release 2 - - - -var groceryList = createTodoList(); -groceryList.add('bread'); -groceryList.add('cheese'); -groceryList.add('milk'); -groceryList.list(); //-> [ -// {description: 'bread', completed: false}, -// {description: 'cheese', completed: false}, -// {description: 'milk', completed: false}, -// ]; -groceryList.indexOf('cheese'); //-> 1 -groceryList.get(1); //-> {description: 'cheese', completed: false} -groceryList.complete(1); -groceryList.list(); //-> [ -// {description: 'bread', completed: false}, -// {description: 'cheese', completed: true}, -// {description: 'milk', completed: false}, -// ]; -groceryList.remove(1); -groceryList.list(); //-> [ -// {description: 'bread', completed: false}, -// {description: 'milk', completed: false}, -// ];