Advertisement
ilkisha

Coffee Machine

Jan 17th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.     let coffeeCaffeine = 0.80;
  3.     let coffeeDecaf = 0.90;
  4.     let tea = 0.80;
  5.     let totalPrice = 0;
  6.     for(let currOrders of array) {
  7.         let change = 0;
  8.         let moneyNeeded = 0;
  9.         let currPrice = 0;
  10.         let currOrder = currOrders.split(', ');
  11.         let insertedCoins = +currOrder[0];
  12.         let typeOfDrink = currOrder[1];
  13.         let quantitySugar = +currOrder[currOrder.length - 1];
  14.         if(typeOfDrink === "coffee"){
  15.             if(currOrder.includes("caffeine") && currOrder.includes("milk") && quantitySugar > 0) {
  16.                 currPrice += coffeeCaffeine + 0.10 + 0.10;
  17.             }
  18.             else if(currOrder.includes("caffeine") && currOrder.includes("milk") && quantitySugar === 0){
  19.                 currPrice += coffeeCaffeine + 0.10;
  20.             }
  21.             else if(currOrder.includes("caffeine") && currOrder.includes("milk") === false && quantitySugar > 0){
  22.                 currPrice += coffeeCaffeine + 0.10;
  23.             }
  24.             else if(currOrder.includes("caffeine") && currOrder.includes("milk") === false && quantitySugar === 0) {
  25.                 currPrice += coffeeCaffeine;
  26.             }
  27.             if(currOrder.includes("decaf") && currOrder.includes("milk") && quantitySugar > 0) {
  28.                 currPrice += coffeeDecaf + 0.10 + 0.10;
  29.             }
  30.             else if(currOrder.includes("decaf") && currOrder.includes("milk") && quantitySugar === 0){
  31.                 currPrice += coffeeDecaf + 0.10;
  32.             }
  33.             else if(currOrder.includes("decaf") && currOrder.includes("milk") === false && quantitySugar > 0){
  34.                 currPrice += coffeeDecaf + 0.10;
  35.             }
  36.             else if (currOrder.includes("decaf") && currOrder.includes("milk") === false && quantitySugar === 0){
  37.                 currPrice += coffeeDecaf;
  38.             }
  39.         }
  40.         else if(typeOfDrink === "tea") {
  41.             if(currOrder.includes("milk") && quantitySugar > 0) {
  42.                 currPrice += tea + 0.10 + 0.10;
  43.             }
  44.             else if(currOrder.includes("milk") && quantitySugar === 0) {
  45.                 currPrice += tea + 0.10;
  46.             }
  47.             else if(currOrder.includes("milk") === false && quantitySugar > 0) {
  48.                 currPrice += tea + 0.10;
  49.             }
  50.             else if (currOrder.includes("milk") === false && quantitySugar === 0){
  51.                 currPrice += tea;
  52.             }
  53.         }
  54.         if(insertedCoins >= currPrice) {
  55.             change = insertedCoins - currPrice;
  56.             totalPrice += currPrice;
  57.             console.log(`You ordered ${typeOfDrink}. Price: ${currPrice.toFixed(2)}$ Change: ${change.toFixed(2)}$`);
  58.         }
  59.         else {
  60.             moneyNeeded = currPrice - insertedCoins;
  61.             console.log(`Not enough money for ${typeOfDrink}. Need ${moneyNeeded.toFixed(2)}$ more.`);
  62.         }
  63.     }
  64.     console.log(`Income Report: ${totalPrice.toFixed(2)}$`);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement