js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Improve the todo list you have built using an object #380

Closed odv closed 4 years ago

odv commented 4 years ago
RazvanBugoi commented 4 years ago

In my app I've named everything with an 's' at the end : 'todos', ' addTodos' and so on. Are you talking about these ones or new ones?

'addTodo' should add objects where? And how many?

'changeTodo should change the todoText property' you mean change the 'todos' list which is an array containing strings to something else?

'toggleCompleted should change the completed property' what property? Change it into what?

RazvanBugoi commented 4 years ago
let toDoApp = {
    todos: [],
    displayTodos: function() {
        console.log(`mytodos:${this.todos}`);
    },
    addTodos: function(input) {
        this.todos.push({
            todoText: input,
            completed: false
        });
        this.displayTodos();
    },
    changeTodos: function(output, position) {
        this.todos[position].todoText = output;
        this.displayTodos();
    },
    toggleCompleted: function(pos) {
        this.todos[pos].completed = !this.todos[pos].completed;
        this.displayTodos();
    },
    deleteTodos: function(element) {
        this.todos.splice(element, 1);
        this.displayTodos();
    },
    deleteAllTodos: function() {
        this.todos = [];
        this.displayTodos();
    }

};