Advertisement
Guest User

Untitled

a guest
May 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.  
  3.     let totalIncome = 0;
  4.     let blank = [];
  5.     for (let i = 0; i < input.length; i++){
  6.     let splitThatShit = input[i].split(", ");
  7.     for(let j = 0;j < splitThatShit.length;j++){
  8.         blank.push(splitThatShit[j]);
  9.         }
  10.     }
  11.  
  12.     let array = blank;
  13.  
  14.     for (let i = 0;i < array.length;i++){
  15.         let coinsInserted = Number(array[i]);
  16.         let typeOfDrink = array[i + 1];
  17.         let drinkCost = 0;
  18.         let sugarAmount = 0;
  19.         let success = false;
  20.         if (typeOfDrink === 'coffee'){
  21.            if (array[i + 2] === 'caffeine'){
  22.                drinkCost = 0.8;
  23.            }
  24.            else if(array[i + 2] === 'decaf'){
  25.                drinkCost = 0.9;
  26.            }
  27.            if (array[i + 3] === 'milk'){
  28.                let rounded =
  29.                drinkCost = (drinkCost + (drinkCost * 0.1));
  30.                drinkCost = Math.round(drinkCost * 10) / 10;
  31.                sugarAmount = Number(array[i + 4]);
  32.            }
  33.            else
  34.            {
  35.                sugarAmount = Number(array[i + 3]);
  36.            }
  37.            success = true;
  38.         }
  39.         else if(typeOfDrink === 'tea'){
  40.             drinkCost = 0.8;
  41.             if (array[i + 2] === 'milk'){
  42.                 drinkCost = drinkCost + (drinkCost * 0.1);
  43.                 drinkCost = Math.round(drinkCost * 10)/10;
  44.                 sugarAmount = Number(array[i + 3]);
  45.             }
  46.             else
  47.             {
  48.                 sugarAmount = Number(array[i + 2]);
  49.             }
  50.             success = true;
  51.         }
  52.         if (success) {
  53.             if (sugarAmount > 0){
  54.                 drinkCost += 0.10;
  55.             }
  56.  
  57.             if (drinkCost <= coinsInserted){
  58.                 let change = coinsInserted - drinkCost;
  59.                 console.log(`You ordered ${typeOfDrink}. Price: \$${drinkCost.toFixed(2)} Change: \$${change.toFixed(2)}`);
  60.                 totalIncome+=drinkCost;
  61.             }
  62.             else{
  63.                 let difference = drinkCost - coinsInserted;
  64.                 console.log(`Not enough money for ${typeOfDrink}. Need \$${difference.toFixed(2)} more.`);
  65.             }
  66.         }
  67.  
  68.     }
  69.  
  70.     console.log(`Income Report: \$${totalIncome.toFixed(2)}`);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement