impactbyte-igneel / projects

🌐 Projects
https://gitlab.com/impactbyte/learn/course-fullstackweb?nav_source=navbar
The Unlicense
0 stars 0 forks source link

Project JavaScript Todos Console #18

Open haydanu opened 5 years ago

krowter commented 5 years ago

https://github.com/krowter/project-javascript-todos-console

aditilham commented 5 years ago

https://github.com/aditilham/project-javascript-todos-console

trie168 commented 5 years ago

https://github.com/trie168/014-project-javascript-todo

fadhilahade commented 5 years ago

https://github.com/fadhilahade/project-javascript-todos-console

dearetta commented 5 years ago

https://github.com/dearetta/project-todos-console

Sumapraja commented 5 years ago

https://github.com/Sumapraja/project-javascript-todos-console

haydanu commented 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);