Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function coffeeMachine(input) {
- let coffee = input[0];
- let sugar = input[1];
- let count = Number(input[2]);
- let sum = count;
- if (coffee === "Espresso") {
- if (sugar === "Without") {
- sum *= 0.9 * 0.65;
- } else if (sugar === "Extra") {
- sum *= 1.2;
- }
- if (count > 5) {
- sum *= 0.75;
- }
- } else if (coffee === "Cappuccino") {
- if (sugar === "Without") {
- sum *= 0.65;
- } else if (sugar === "Normal") {
- sum *= 1.2;
- } else {
- sum *= 1.6;
- }
- } else {
- if (sugar === "Without") {
- sum *= 0.5 * 0.65;
- } else if (sugar === "Normal") {
- sum *= 0.6;
- } else {
- sum *= 0.7;
- }
- }
- if (sum > 15) {
- sum *= 0.8;
- }
- console.log(`You bought ${count} cups of ${coffee} for ${sum.toFixed(2)} lv.`);
- }
- РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
- function coffeeMachine(input) {
- let coffee = input[0];
- let sugar = input[1];
- let count = Number(input[2]);
- let sum = count;
- switch (coffee) {
- case "Espresso":
- sum *= (sugar === "Without" ? 0.9 * 0.65 : sugar === "Extra" ? 1.2 : 1) * (count > 5 ? 0.75 : 1);
- break;
- case "Cappuccino":
- sum *= sugar === "Without" ? 0.65 : sugar === "Extra" ? 1.6 : 1.2;
- break;
- case "Tea":
- sum *= sugar === "Without" ? 0.5 * 0.65 : sugar === "Extra" ? 0.7 : 0.6;
- break;
- }
- console.log(`You bought ${count} cups of ${coffee} for ${(sum * (sum > 15 ? 0.8 : 1)).toFixed(2)} lv.`);
- }
- РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
- function coffeeMachine(input) {
- let coffee = input[0];
- let sugar = input[1];
- let count = Number(input[2]);
- let sum = (coffee === "Espresso" ? ((sugar === "Without" ? 0.9 * 0.65 : sugar === "Extra" ? 1.2 : 1) * (count > 5 ? 0.75 : 1)) :
- coffee === "Cappuccino" ? (sugar === "Without" ? 0.65 : sugar === "Extra" ? 1.6 : 1.2) :
- (sugar === "Without" ? 0.5 * 0.65 : sugar === "Extra" ? 0.7 : 0.6)) * count;
- console.log(`You bought ${count} cups of ${coffee} for ${(sum * (sum > 15 ? 0.8 : 1)).toFixed(2)} lv.`);
- }
Add Comment
Please, Sign In to add comment