Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function coffeeMachine(input) {
- let drink = String(input.shift());
- let sugar = String(input.shift());
- let count = Number(input.shift());
- switch (drink) {
- case 'Espresso':
- switch (sugar) {
- case 'Without':
- if (count >= 5) {
- price = 0.90;
- discount1 = price - price * 0.35;
- discount2 = discount1 - discount1 * 0.25;
- totalSum = count * discount2;
- } else if (count < 5) {
- price = 0.90;
- discount = price - price * 0.35;
- totalSum = count * discount;
- }
- break;
- case 'Normal':
- if (count >= 5) {
- price = 1;
- discount = price - price * 0.25;
- totalSum = count * discount;
- } else if (count < 5) {
- price = 1;
- totalSum = count * price;
- }
- break;
- case 'Extra':
- if (count >= 5) {
- price = 1.2;
- discount = price - price * 0.25;
- totalSum = count * discount;
- } else if (count < 5) {
- price = 1.2;
- totalSum = count * price;
- }
- break;
- }
- break;
- case 'Cappuccino':
- switch (sugar) {
- case 'Without':
- price = 1.00;
- discount = price - price * 0.35;
- totalSum = count * discount;
- break;
- case 'Normal':
- price = 1.20;
- totalSum = count * price;
- break;
- case 'Extra':
- price = 1.60;
- totalSum = count * price;
- break;
- }
- case 'Tea':
- switch (sugar) {
- case 'Without':
- price = 0.50;
- discount = price - price * 0.35;
- totalSum = count * discount;
- break;
- case 'Normal':
- price = 0.60;
- totalSum = count * price;
- break;
- case 'Extra':
- price = 0.70;
- totalSum = count * price;
- break;
- }
- break;
- }
- break;
- if (totalSum <= 15) {
- console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum).toFixed(2)} lv.`));
- } else {
- console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum - totalSum * 0.20).toFixed(2)} lv.`));
- }
- }
- coffeeMachine(['Cappuccino', 'Normal', 13]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement