DEV Community

Discussion on: Daily Challenge #56 - Coffee Shop

Collapse
 
chrisachard profile image
Chris Achard

I did it three different ways, but here's what I ended up with as probably the cleanest:

JS

const coffee = (amount) => {
  let drinktype = {
    2.2: "Americano",
    2.3: "Latte",
    2.4: "Flat white",
    3.5: "Filter",
  }[amount]

  if(drinktype) {
    return "Here is your "+drinktype+", have a nice day!"
  } else {
    return "Sorry, exact change only, try again tomorrow!"
  }
}
Enter fullscreen mode Exit fullscreen mode

You can watch me solve it here, plus see the other two solutions (and a bonus discussion about why not to use floats for currency in JS 😂): youtu.be/HtvBlId7tig