Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function demo(arr){
- let sum = 0;
- for(let i = 0; i < arr.length; i++){
- let split = arr[i].split(", ");
- let availableAmount = +split[0];
- let sugar = split[split.length - 1];
- let cost;
- if(split.includes("coffee") && split.includes("caffeine")) {
- cost = 0.80;
- if(split.includes("milk")){
- cost = +cost + +(cost * 0.1).toFixed(1);
- }
- if(sugar > 0){
- cost = +cost + 0.1;
- }
- let change = Math.abs(cost - availableAmount);
- if(cost <= availableAmount) {
- sum = +sum + +cost;
- console.log(`You ordered coffee. Price: ${cost.toFixed(2)}$ Change: ${change.toFixed(2)}$`);
- }else {
- console.log(`Not enough money for coffee. Need ${cost.toFixed(2)}$ more.`);
- }
- } else if(split.includes("coffee") && split.includes("decaf")) {
- cost = 0.90;
- if(split.includes("milk")){
- cost = +cost + +(cost * 0.1).toFixed(1);
- }
- if(sugar > 0){
- cost = +cost + 0.1;
- }
- let change1 = Math.abs(cost - availableAmount);
- if(cost <= availableAmount) {
- sum = +sum + +cost;
- console.log(`You ordered coffee. Price: ${cost.toFixed(2)}$ Change: ${change1.toFixed(2)}$`);
- }else {
- console.log(`Not enough money for coffee. Need ${cost.toFixed(2)}$ more.`);
- }
- } else if (split.includes("tea")){
- cost = 0.80;
- if(split.includes("milk")){
- cost = +cost + +(cost * 0.1).toFixed(1);
- }
- if(sugar > 0){
- cost = +cost + 0.1;
- }
- let changeTea = Math.abs(cost - availableAmount);
- if(cost <= availableAmount) {
- sum = sum + +cost;
- console.log(`You ordered tea. Price: ${cost.toFixed(2)}$ Change: ${changeTea.toFixed(2)}$`);
- }else {
- console.log(`Not enough money for tea. Need ${changeTea.toFixed(2)}$ more.`);
- }
- }
- }
- console.log(`Income Report: ${sum.toFixed(2)}$`);
- }
Advertisement
Add Comment
Please, Sign In to add comment