Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var todoList = {
- todos: [],
- displayTodos: function() {
- if (this.todos.length === 0) {
- console.log('The list is empty.');
- } else {
- console.log('Todo List:');
- for (var i = 0; i < this.todos.length; i++) {
- if (this.todos[i].completed === true) {
- console.log('(X)', this.todos[i].info);
- } else {
- console.log('( )', this.todos[i].info);
- }
- }
- }
- },
- addTodos: function(todoText) {
- this.todos.push({
- info: todoText,
- completed: false //Boolean true or false
- });
- this.displayTodos();
- },
- changeTodo: function(position, todoText) {
- this.todos[position].info = todoText;
- this.displayTodos();
- },
- deleteTodo: function(position) {
- this.todos.splice(position, 1);
- this.displayTodos();
- },
- toggleCompleted: function(position) {
- var todo = this.todos[position];
- todo.completed = !todo.completed;
- this.displayTodos();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement