diff --git a/que_hacer.html b/que_hacer.html new file mode 100644 index 0000000..9cbc93e --- /dev/null +++ b/que_hacer.html @@ -0,0 +1,10 @@ + + + + Que Hacer List + + + + + + diff --git a/que_hacer.js b/que_hacer.js new file mode 100644 index 0000000..266d562 --- /dev/null +++ b/que_hacer.js @@ -0,0 +1,86 @@ + +// Todo is a format that I want to use 10000000 times +var Todo = function(){ + this.tasks = [] +}; + + var Task = function(newTask) { + this.id = 0, + this.description = newTask, + this.completed = false +} + +// set of functions that ALL instances of the Todo object will inherit +Task.prototype.complete = function() { + this.completed = true +} + +Todo.prototype.add = function(newTask) { + var task = new Task(newTask) + this.tasks.push(task) + task.id = this.tasks.length +}; + +// outside the Todo object literal to avoid making a copy EACH time +// you have a new task + +Todo.prototype.remove = function(deleteMe) { + for (var i=0; i<=this.tasks.length; i++) { + console.log(this.tasks[i]) + console.log(deleteMe) + if (deleteMe === this.tasks[i]){ + console.log("I just deleted: "); + this.tasks.splice(i,1); + } + } +} + +// display each task in the instance's array +Todo.prototype.list = function () { + for (var i in this.tasks) { + console.log(this.tasks[i]); + } +} + +// instance of our Todo +var groceryList = new Todo(); +groceryList.add("chocolate") +groceryList.add("bread") +groceryList.add("peanut butter") +groceryList.list(); + +// expect to remove chocolate from the array +// groceryList.remove("chocolate") +// groceryList.remove("bread") +// groceryList.list(); + + +var yourPantry = new Todo(); +yourPantry.add("rice") +yourPantry.add("potatos") +yourPantry.list(); + + +// go get the rice and check it off on the list which is stored as an array +//gets the 'rice' from the tasks array +var completeRice = yourPantry.tasks[0]; +//expect to see the ID associated with rice +// completeRice.id +// completeRice.description +completeRice.complete(); +console.log(completeRice) + +// delete rice from the list +yourPantry.remove(completeRice) + +// should return FALSE in console and it does! +// console.log("chocolate" !== groceryList.tasks[1]) + +var partyStuff = new Todo(); + + + +// another way to see what is going on with just addTask and just list +// Todo.prototype = { +// addTask: function() {}, +// list: function() {}, diff --git a/todo_list.js b/todo_list.js index 110fce6..cb5fc7f 100644 --- a/todo_list.js +++ b/todo_list.js @@ -1,10 +1,37 @@ -var newTodoList = function() { - // ??? +NewTodoList = function() { + this.tasks = [] }; +NewTodoList.prototype.add = function(item) { + this.tasks.push(item); +} + +NewTodoList.prototype.list = function() { + NewObject = function(id, description) { + var printTasks = { + id: id, + description: description, + completed: false, + } + } +} // Driver code -var todoList = newTodoList(); \ No newline at end of file +var todoList = new NewTodoList(); + +todoList.add('banana'); +todoList.add('cheese'); +console.log(todoList.tasks) +todoList.list(); + + +// this creates another copy of newTodoList +// gives us access to the tasks array outside the object literal +// var cookies = new NewTodoList(); +// cookies.add('chocolate', 30); + +// console.log(cookies.tasks) +