Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cruiseShip(input) {
- let destination = input[0];
- let cabinType = input[1];
- let overnights = Number(input[2]);
- let dayPrice = 0;
- if (destination == "Mediterranean") {
- if (cabinType == "standard cabin") {
- dayPrice = 27.50;
- } else if (cabinType == "cabin with balcony") {
- dayPrice = 30.20;
- } else {
- dayPrice = 40.50;
- }
- } else if (destination == "Adriatic") {
- if (cabinType == "standard cabin") {
- dayPrice = 22.99;
- } else if (cabinType == "cabin with balcony") {
- dayPrice = 25.00;
- } else {
- dayPrice = 34.99;
- }
- } else {
- if (cabinType == "standard cabin") {
- dayPrice = 23.00;
- } else if (cabinType == "cabin with balcony") {
- dayPrice = 26.60;
- } else {
- dayPrice = 39.80;
- }
- }
- let totalSum = dayPrice * 4 * overnights;
- if (overnights > 7) {
- totalSum *= 0.75;
- }
- console.log(`Annie\'s holiday in the ${destination} sea costs ${totalSum.toFixed(2)} lv.`);
- return;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function cruiseShip(input) {
- let destination = input[0];
- let cabinType = input[1];
- let overnights = Number(input[2]);
- let dayPrice =
- destination == "Mediterranean" ?
- (cabinType == "standard cabin" ? 27.50 : cabinType == "cabin with balcony" ? 30.20 : 40.50) :
- destination == "Adriatic" ?
- (cabinType == "standard cabin" ? 22.99 : cabinType == "cabin with balcony" ? 25.00 : 34.99) :
- (cabinType == "standard cabin" ? 23.00 : cabinType == "cabin with balcony" ? 26.60 : 39.80);
- let totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
- console.log(`Annie\'s holiday in the ${destination} sea costs ${totalSum.toFixed(2)} lv.`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement