DEV Community

Umar Shahzad
Umar Shahzad

Posted on

JavaScript

var alcoholic = ["Beer","Wine","Cider","Cocktail","Shots"];
var soft = ["Coke","Fanta","Sprite","Dr.Pepper", "Mountain Dew", "Pepsi"];
var hot = ["Coffee", "Cappuccino", "Espresso", "Hot Chocolate", "Latte"];
var cold = ["Lemonade","Juice","Smoothie","Milkshake","Ice tea"];

var drinks = [alcoholic, soft, hot, cold];

printDrinks = (order_number) => {
if(order_number > 0 || order_number > 3) {
return 'INVALID_ORDER_NUMBER';
}
for (i=0; i < drinks[order_number].length; i++) {
console.log(drinks[order_number][i]);
}
}

printAllDrinks = () => {
for(i = 0; i < drinks.length; i++) {
for(j=0; j < drinks[i].length; j++) {
console.log(drinks[i][j]);
}
}
}

searchForDrink = (drink) => {
for(i = 0; i < drinks.length; i++) {
for(j=0; j < drinks[i].length; j++) {
if(drink == drinks[i][j]) {
return true;
}
}
}
return false;
}

var search = prompt('which drink would you like?');

if(searchForDrink(search)) {
alert('Drink available');
} else {
alert('Sorry!, drink not available');
}

printDrinks(0);

console.log('===============');

printDrinks(1);

console.log('===============');

printDrinks(2);

console.log('===============');

printDrinks(3);

console.log('===============');

printDrinks(4);

when enter 1 in the prompt, it should show the drinks in the array 1 with alert. And then it should show another prompt where you write drink name from the number 1 as example. And then it should tell if it is available or not.

javascript

Top comments (0)