Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- РЕШЕНИЕ С IF-ELSE:
- function skiTrip(input) {
- let night = Number(input[0]) - 1;
- let room = input[1];
- let rating = input[2];
- let priceForRoom = 18;
- let priceForApartment = 25;
- let priceForPresidentApartment = 35;
- let totalSum = 0;
- if (room == "room for one person") {
- totalSum = priceForRoom * night;
- } else if (room == "apartment") {
- totalSum = priceForApartment * night;
- if (night < 10) {
- totalSum *= 0.70;
- } else if (night >= 10 && night < 15) {
- totalSum *= 0.65;
- } else if (night >= 15) {
- totalSum *= 0.5;
- }
- } else if (room == "president apartment") {
- totalSum = priceForPresidentApartment * night;
- if (night < 10) {
- totalSum *= 0.90;
- } else if (night >= 10 && night < 15) {
- totalSum *= 0.85;
- } else if (night >= 15) {
- totalSum *= 0.80;
- }
- }
- if (rating == "positive") {
- totalSum *= 1.25;
- } else if (rating == "negative") {
- totalSum *= 0.90;
- }
- console.log(`${totalSum.toFixed(2)}`);
- }
- РЕШЕНИЕ СЪС SWITCH I IF-ELSE:
- function skiTrip(input) {
- let night = Number(input[0]) - 1;
- let room = input[1];
- let rating = input[2];
- let priceForRoom = 18;
- let priceForApartment = 25;
- let priceForPresidentApartment = 35;
- let totalSum = 0;
- switch (room){
- case "room for one person":
- totalSum = priceForRoom * night;
- break;
- case "apartment":
- totalSum = priceForApartment * night;
- if (night < 10) {
- totalSum *= 0.70;
- } else if (night >= 10 && night < 15) {
- totalSum *= 0.65;
- } else if (night >= 15) {
- totalSum *= 0.5;
- }
- break;
- case "president apartment":
- totalSum = priceForPresidentApartment * night;
- if (night < 10) {
- totalSum *= 0.90;
- } else if (night >= 10 && night < 15) {
- totalSum *= 0.85;
- } else if (night >= 15) {
- totalSum *= 0.80;
- }
- break;
- }
- if (rating == "positive") {
- totalSum *= 1.25;
- } else if (rating == "negative") {
- totalSum *= 0.90;
- }
- console.log(`${totalSum.toFixed(2)}`);
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function skiTrip(input) {
- let night = Number(input[0]) - 1;
- let room = input[1];
- let rating = input[2];
- let totalSum = ((room == "room for one person" ? 18 :
- room == "apartment" ? (25 * (night < 10 ? 0.7 : night >= 15 ? 0.5 : 0.65)) :
- (35 * (night < 10 ? 0.9 : night >= 15 ? 0.8 : 0.85))) * night) * (rating == "positive" ? 1.25 : 0.9);
- console.log(`${totalSum.toFixed(2)}`);
- }
- ИЛИ ТАРИКАТСКАТА:)
- function skiTrip(input) {
- let night = Number(input[0]) - 1;
- console.log(`${(((input[1] == "room for one person" ? 18 :
- input[1] == "apartment" ? (25 * (night < 10 ? 0.7 : night >= 15 ? 0.5 : 0.65)) :
- (35 * (night < 10 ? 0.9 : night >= 15 ? 0.8 : 0.85))) * night) * (input[2] == "positive" ? 1.25 : 0.9)).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement