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
38 changes: 34 additions & 4 deletions todo_list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
var newTodoList = function() {
// ???
// function ToDoList() {
// this.tasks = []
// }

function Task(task) {
this.task = task,
this.completed = false,
this.description = 'buy ' + task
};

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

function ToDoList() {
this.tasks = [];
};

// Driver code

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() {
for (i=0; i < this.tasks.length; i++) {
console.log(this.tasks[i]);
}
};



fooList = new ToDoList();
fooList.add('sweet stuff');
fooList.add('foo foo');

// Driver code

var todoList = newTodoList();