Skip to content

Instantly share code, notes, and snippets.

@DoviMaj
Created May 31, 2020 21:41
Show Gist options
  • Save DoviMaj/8968e4dc7ea449f2f81588ba4ea70f57 to your computer and use it in GitHub Desktop.
Save DoviMaj/8968e4dc7ea449f2f81588ba4ea70f57 to your computer and use it in GitHub Desktop.
todoList
<!DOCTYPE html>
<html>
<head>
<title>Practical JS</title>
</head>
<body>
<script>
let todosList = {
todos: [],
displayTodos: function(){
if(this.todos.lenght === 0){
console.log("your list is empty");
} else {
console.log("My Todos:");
for(var i = 0; i < this.todos.length; i++){
console.log(this.todos[i].todoText);
}
}
},
addTodo: function(todoText){
this.todos.push({
todoText: todoText,
completed: false
});
this.displayTodos();
},
changeTodo: function(position, todoText){
this.todos[position].todoText = todoText;
this.displayTodos();
},
deleteTodo: function(position){
this.todos.splice(position, 1);
this.displayTodos();
},
toggleCompleted: function(position){
this.todos[position].completed = !this.todos[position].completed;
this.displayTodos();
}
}
</script>
</body>
</html>
@KunleTayo
Copy link

Your line 12 reads:
if(this.todos.lenght === 0){

It should read:
if(this.todos.length === 0){

Correction

@DoviMaj
Copy link
Author

DoviMaj commented Jun 1, 2020

Thanks. Shouldn't the console have cought that error?

@KunleTayo
Copy link

I guess you are right. There is no Javascript property for an array called Array.lenght

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment