Open haydanu opened 5 years ago
const todos = [];
function addTodo(todo) {
return todos.push(todo);
}
function deleteTodo(index) {
return todos.splice(index, 1);
}
function findTodo(todoList) {
const theTodo = todos.find(element => element === todoList);
console.log("ini hasil temuannya", theTodo);
return theTodo;
}
function updateTodo(oldTodo, newTodo) {
let theTodoIndex = todos.findIndex(element => element === oldTodo);
todos.splice(theTodoIndex, 1, newTodo);
return todos;
}
addTodo("eat");
addTodo("learn");
// deleteTodo(0);
// findTodo("eat");
console.log("todos before update", todos);
updateTodo("learn", "sleep");
console.log("todos after update", todos);
https://github.com/krowter/project-javascript-todos-console