Noob在这里。因此,我正在通过Colt Steele的Web开发人员Bootcamp进行工作,我真的很困。我只是无法运行这段代码,而是直接从Colt复制该代码。该代码将一直运行,直到在if语句中达到forEach为止。它应该(您可能知道)遍历数组和console.log列表中的数组中的每个项目,但这只是行不通,我也不知道为什么。我非常感谢您的指导。这是代码,在此先感谢您。
window.setTimeout(function() {
var todos = ["buy new turtle"];
var input = prompt("what would you like to do?");
while (input !== "quit") {
if (input === "list") {
todos.forEach(function(todo) {
console.log(todo);
});
} else if (input === "new") {
var newTodo = prompt("enter new todo");
todos.push(newTodo);
}
input = prompt("what would you like to do?");
}
console.log("ok, you quit the app");
}, 500);