Created
March 29, 2016 11:43
-
-
Save iamkarsoft/44b7283d1e1d72a89ca3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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