samedi 29 juin 2019

Stuck in else if loop in Javascript

I'm doing an exercise for a class and we are creating a todo list. My issue is that when I type in my todo and press enter I get the message "Enter new todo", instead of "Added todo". It seems I'm stuck in this else if loop and it won't go to the next else if statement.

var todos = ["Buy New Turtle"];

window.setTimeout(function() {

  var input = prompt("What would you like to do?");

  while(input !== "quit") {

    if(input === "list") {
      console.log("**********");
      todos.forEach(function(todo, i) {
        console.log(i + ": " + todo);
      })
      console.log("**********")
    }
    else if(input === "new") {
      var newTodo = prompt("Enter new todo");
      todos.push(newTodo);
      console.log("Added todo");
      }

    else if(input === "delete"){
      var index = prompt("Enter index of todo to delete");
      todos.splice(index, 1);
      }
  }
    input = prompt("What would you like to do?");

  console.log("OK, YOU QUIT THE APP");
}, 500);

Aucun commentaire:

Enregistrer un commentaire