Skip to content

Instantly share code, notes, and snippets.

@iamkarsoft
Created March 29, 2016 11:43
Show Gist options
  • Save iamkarsoft/44b7283d1e1d72a89ca3 to your computer and use it in GitHub Desktop.
Save iamkarsoft/44b7283d1e1d72a89ca3 to your computer and use it in GitHub Desktop.
var Todo = ["buy car"];
var input = prompt("What would you like to do");
while(input!=="quit"){
if(input==="list"){
listTodos();
}else if(input ==="new"){
addTodo();
}else if(input==="delete"){
deleteTodo();
}
//ask again for new input
input = prompt("What would you like to do");
}
console.log("ok, you quit");
function addTodo(){
var newTodo = prompt("Enter new todo");
Todo.push(newTodo);
console.log("Added Todo");
}
function listTodos(){
console.log("**********");
Todo.forEach(function(todo, i){
console.log(i+" : "+todo);
});
console.log("**********");
}
function deleteTodo(){
var index=prompt("what is the index to delete");
Todo.splice(index, 1);
console.log("Deleted Todo");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment