Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function excursionCalculator(input) {
- let people = Number(input[0]);
- let season = input[1];
- let price = 0;
- if (season == "spring") {
- if (people <= 5) {
- price = 50;
- } else {
- price = 48;
- }
- } else if (season == "summer") {
- if (people <= 5) {
- price = 48.50;
- } else {
- price = 45;
- }
- } else if (season == "autumn") {
- if (people <= 5) {
- price = 60;
- } else {
- price = 49.50;
- }
- } else if (season == "winter") {
- if (people <= 5) {
- price = 86;
- } else {
- price = 85;
- }
- }
- if (season == "summer") {
- price *= 0.85;
- } else if (season == "winter") {
- price *= 1.08;
- }
- console.log(`${(price * people).toFixed(2)} leva.`);
- }
- РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
- function excursionCalculator(input) {
- let people = Number(input[0]);
- let season = input[1];
- let price = 0;
- switch (season) {
- case "spring":
- price = people <= 5 ? 50 : 48;
- break;
- case "summer":
- price = people <= 5 ? 48.50 : 45;
- break;
- case "autumn":
- price = people <= 5 ? 60 : 49.50;
- break;
- case "winter":
- price = people <= 5 ? 86 : 85;
- break;
- }
- price *= season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1;
- console.log(`${(price * people).toFixed(2)} leva.`);
- }
- РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
- function excursionCalculator(input) {
- let people = Number(input[0]);
- let season = input[1];
- let price = (season == "spring" ? (people <= 5 ? 50 : 48) :
- season == "summer" ? (people <= 5 ? 48.50 : 45) :
- season == "autumn" ? (people <= 5 ? 60 : 49.50) :
- season == "winter" ? (people <= 5 ? 86 : 85) : 0) *
- (season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1) * people;
- console.log(`${price.toFixed(2)} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement