A simple Javascript solution using nested ternary operators.
constcoffeeShop=(order="Water",cash=0)=>{constdrinks=[{name:"Americano",cost:2.2},{name:"Latte",cost:2.3},{name:"Flat White",cost:2.4},{name:"Filter",cost:3.5}];constrequest=drinks.filter(drink=>drink.name==order);request[0]==null?console.log(`We do not serve ${order} here. Try some Filter tomorrow.`):request[0].cost==cash?console.log(`Here is your ${request[0].name}, have a nice day!`):console.log("Sorry, exact change only, try again tomorrow!");};
Works fine
coffeeShop();//We do not serve Water here. Try some Filter tomorrow!coffeeShop("Americano",2.2);//Here is your Americano, have a nice day!coffeeShop("Americano",2.5);//Sorry, exact change only, try again tomorrow!coffeeShop("Filter",3.5);//Here is your Filter, have a nice day!coffeeShop("Mocha",3.5);//We do not serve Mocha here. Try some Filter tomorrow!!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A simple Javascript solution using nested ternary operators.
Works fine