Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function santasHoliday(input) {
- let days = Number(input[0]) - 1;
- let type = input[1];
- let rating = input[2];
- let price = 0;
- if (days > 0) {
- if (type == "room for one person") {
- price = 18;
- } else if (type == "apartment") {
- price = 25;
- if (days < 10) {
- price *= 0.7;
- } else if (days > 15) {
- price *= 0.5;
- } else {
- price *= 0.65;
- }
- } else if (type == "president apartment") {
- price = 35;
- if (days < 10) {
- price *= 0.9;
- } else if (days > 15) {
- price *= 0.8;
- } else {
- price *= 0.85;
- }
- }
- if (rating == "positive") {
- price *= 1.25;
- } else {
- price *= 0.9;
- }
- price *= days;
- }
- console.log(`${price.toFixed(2)}`);
- }
- РЕШЕНИЕ С IF И ТЕРНАРЕН ОПЕРАТОР:
- function santasHoliday(input) {
- let days = Number(input[0]) - 1;
- let type = input[1];
- let rating = input[2];
- let price = 0;
- if (days > 0) {
- price = type == "room for one person" ? 18 : type == "apartment" ? 25 : 35;
- if (days < 10) {
- price *= type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1;
- } else if (days > 15) {
- price *= type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1;
- } else {
- price *= type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1;
- }
- price *= days * (rating == "positive" ? 1.25 : 0.9);
- }
- console.log(`${price.toFixed(2)}`);
- }
- РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
- function santasHoliday(input) {
- let days = Number(input[0]) - 1;
- let type = input[1];
- let rating = input[2];
- let price = days > 0 ? ((type == "room for one person" ? 18 : type == "apartment" ? 25 : 35) *
- (days < 10 ? (type == "apartment" ? 0.7 : type == "president apartment" ? 0.9 : 1) :
- days > 15 ? (type == "apartment" ? 0.5 : type == "president apartment" ? 0.8 : 1) :
- (type == "apartment" ? 0.65 : type == "president apartment" ? 0.85 : 1)) *
- (rating == "positive" ? 1.25 : 0.9) * days) : 0;
- console.log(`${price.toFixed(2)}`);
- }
Add Comment
Please, Sign In to add comment