Skip to content

Instantly share code, notes, and snippets.

@marc-lapierre
Created May 22, 2022 21:34
Show Gist options
  • Save marc-lapierre/956fe11ecfa441ceded78dfe68a5156b to your computer and use it in GitHub Desktop.
Save marc-lapierre/956fe11ecfa441ceded78dfe68a5156b to your computer and use it in GitHub Desktop.
todo.js
console.warn('Program - Started')
let input = prompt('what would you like to do?')
const todos = ['Walk the dog', 'Order Pizza']
while (input !== 'quit' && input !== 'q') {
if (input === 'list') {
console.log('**************************')
for (let i = 0; i < todos.length; i++) {
console.log(`${i}: ${todos[i]}`)
}
console.log('**************************')
} else if (input === 'new') {
const newTodo = prompt('Enter new task')
todos.push(newTodo)
console.log(`${newTodo} - Added`)
} else if (input === 'delete') {
const index = parseInt(prompt('Enter index to delete'))
if (!Number.isNaN(index)) {
const deletedTask = todos.splice(index, 1)
console.log(`${deletedTask[0]} - Deleted`)
} else {
console.log('Unknown Index')
}
}
input = prompt('what would you like to do?')
}
console.warn('Program - Closed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment