Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function travelAgency(input) {
- let town = input[0];
- let pack = input[1];
- let vip = input[2]
- let days = Number(input[3]);
- if (days > 7) {
- days--;
- }
- let total = days
- if ((town === "Bansko" || town === "Borovets" || town === "Varna" || town === "Burgas") &&
- (pack === "noEquipment" || pack === "withEquipment" || pack === "noBreakfast" || pack === "withBreakfast")) {
- if (days < 1) {
- console.log("Days must be positive number!");
- } else {
- if (town === "Bansko" || town === "Borovets") {
- if (pack === "withEquipment") {
- total *= 100;
- if (vip == "yes") {
- total *= 0.90;
- }
- } else {
- total *= 80
- if (vip == "yes") {
- total *= 0.95;
- }
- }
- } else {
- if (pack == "withBreakfast") {
- total *= 130;
- if (vip == "yes") {
- total *= 0.88;
- }
- } else {
- total *= 100
- if (vip == "yes") {
- total *= 0.93;
- }
- }
- }
- console.log(`The price is ${total.toFixed(2)}lv! Have a nice time!`)
- }
- } else {
- console.log("Invalid input!");
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function travelAgency(input) {
- let town = input[0];
- let pack = input[1];
- let vip = input[2]
- let days = Number(input[3]);
- days -= days > 7 ? 1 : 0;
- let total = (town === "Bansko" || town === "Borovets" ?
- (pack === "withEquipment" ? 100 * (vip == "yes" ? 0.90 : 1) :
- pack === "noEquipment" ? 80 * (vip == "yes" ? 0.95 : 1) : 0) :
- town === "Varna" || town === "Burgas" ? (pack == "withBreakfast" ? 130 * (vip == "yes" ? 0.88 : 1) :
- pack === "noBreakfast" ? 100 * (vip == "yes" ? 0.93 : 1) : 0) : 0) * days;
- console.log(days < 1 ? "Days must be positive number!" : total === 0 ? "Invalid input!" : `The price is ${total.toFixed(2)}lv! Have a nice time!`);
- }
Add Comment
Please, Sign In to add comment