Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- let coffeeCaffeine = 0.80;
- let coffeeDecaf = 0.90;
- let tea = 0.80;
- let totalPrice = 0;
- for(let currOrders of array) {
- let change = 0;
- let moneyNeeded = 0;
- let currPrice = 0;
- let currOrder = currOrders.split(', ');
- let insertedCoins = +currOrder[0];
- let typeOfDrink = currOrder[1];
- let quantitySugar = +currOrder[currOrder.length - 1];
- if(typeOfDrink === "coffee"){
- if(currOrder.includes("caffeine") && currOrder.includes("milk") && quantitySugar > 0) {
- currPrice += coffeeCaffeine + 0.10 + 0.10;
- }
- else if(currOrder.includes("caffeine") && currOrder.includes("milk") && quantitySugar === 0){
- currPrice += coffeeCaffeine + 0.10;
- }
- else if(currOrder.includes("caffeine") && currOrder.includes("milk") === false && quantitySugar > 0){
- currPrice += coffeeCaffeine + 0.10;
- }
- else if(currOrder.includes("caffeine") && currOrder.includes("milk") === false && quantitySugar === 0) {
- currPrice += coffeeCaffeine;
- }
- if(currOrder.includes("decaf") && currOrder.includes("milk") && quantitySugar > 0) {
- currPrice += coffeeDecaf + 0.10 + 0.10;
- }
- else if(currOrder.includes("decaf") && currOrder.includes("milk") && quantitySugar === 0){
- currPrice += coffeeDecaf + 0.10;
- }
- else if(currOrder.includes("decaf") && currOrder.includes("milk") === false && quantitySugar > 0){
- currPrice += coffeeDecaf + 0.10;
- }
- else if (currOrder.includes("decaf") && currOrder.includes("milk") === false && quantitySugar === 0){
- currPrice += coffeeDecaf;
- }
- }
- else if(typeOfDrink === "tea") {
- if(currOrder.includes("milk") && quantitySugar > 0) {
- currPrice += tea + 0.10 + 0.10;
- }
- else if(currOrder.includes("milk") && quantitySugar === 0) {
- currPrice += tea + 0.10;
- }
- else if(currOrder.includes("milk") === false && quantitySugar > 0) {
- currPrice += tea + 0.10;
- }
- else if (currOrder.includes("milk") === false && quantitySugar === 0){
- currPrice += tea;
- }
- }
- if(insertedCoins >= currPrice) {
- change = insertedCoins - currPrice;
- totalPrice += currPrice;
- console.log(`You ordered ${typeOfDrink}. Price: ${currPrice.toFixed(2)}$ Change: ${change.toFixed(2)}$`);
- }
- else {
- moneyNeeded = currPrice - insertedCoins;
- console.log(`Not enough money for ${typeOfDrink}. Need ${moneyNeeded.toFixed(2)}$ more.`);
- }
- }
- console.log(`Income Report: ${totalPrice.toFixed(2)}$`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement