自从我上次尝试在循环内迭代时向用户打印输出以来,浏览器行为似乎已发生变化。我正在尝试验证用户输入,因为它与我的搜索数组中的条件相关,用于简单的库存清单,并且在仍在循环中迭代时将其打印在文档上。现在看来输出只有在你退出循环后才会显示出来。
while (true) {
search = prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit");
search = search.toLowerCase();
if (search === 'quit') {
break;
} else if (search === 'list') {
print(inStock.join(", "));
continue;
} else {
if (inStock.indexOf(search) > -1 ) {
print("Yes, we have " + search + " in the store.");
} else {
print(search + "is not in stock.");
}
}
}
参数:
JSFiddle:https://jsfiddle.net/9nfd62q7/