JSFiddle - React, Tailwind, and code Playground
JavaScript
var stock = ['apples', 'eggs', 'milk', 'cookies', 'cheese', 'bread'];
var exitLoop = false;
function isInStock(check){
var checked = stock.indexOf(check);
while (exitLoop === false) {
if (checked >= 0) {
alert(check + " is in stock.");
isInStock(prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit."));
} else if (check.toLowerCase() === 'list') {
alert(stock.join(', '));
isInStock(prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit."));
} else if(!check || check === "quit") {
alert('Exiting program');
exitLoop = true;
} else {
alert(check + ' is not in stock.');
isInStock(prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit."));
}
}
}
isInStock(prompt("Search for a product in our store. Type 'list' to show all of the produce and 'quit' to exit."));