Advertisement
Spocoman

07. School Camp

Dec 22nd, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function schoolCamp(input) {
  2.     let season = input[0];
  3.     let group = input[1];
  4.     let people = Number(input[2]);
  5.     let nights = Number(input[3]);
  6.     let price = 0;
  7.     let sport = '';
  8.  
  9.     if (season === 'Winter') {
  10.         switch (group) {
  11.             case 'boys':
  12.                 price = 9.60;
  13.                 sport = 'Judo';
  14.                 break;
  15.             case 'girls':
  16.                 price = 9.60;
  17.                 sport = 'Gymnastics';
  18.                 break;
  19.             case 'mixed':
  20.                 price = 10.00;
  21.                 sport = 'Ski';
  22.                 break;
  23.         }
  24.     } else if (season === 'Spring') {
  25.         switch (group) {
  26.             case 'boys':
  27.                 price = 7.20;
  28.                 sport = 'Tennis';
  29.                 break;
  30.             case 'girls':
  31.                 price = 7.20;
  32.                 sport = 'Athletics';
  33.                 break;
  34.             case 'mixed':
  35.                 price = 9.50;
  36.                 sport = 'Cycling';
  37.                 break;
  38.         }
  39.     } else {
  40.         switch (group) {
  41.             case 'boys':
  42.                 price = 15.00;
  43.                 sport = 'Football';
  44.                 break;
  45.             case 'girls':
  46.                 price = 15.00;
  47.                 sport = 'Volleyball';
  48.                 break;
  49.             case 'mixed':
  50.                 price = 20.00;
  51.                 sport = 'Swimming';
  52.                 break;
  53.         }
  54.     }
  55.  
  56.     if (people >= 50) {
  57.         price *= 0.50;
  58.     } else if (people >= 20) {
  59.         price *= 0.85;
  60.     }  else if (people >= 10) {
  61.         price *= 0.95;
  62.     }
  63.  
  64.     let total = price * people * nights;
  65.     console.log(`${sport} ${total.toFixed(2)} lv.`);
  66. }
  67.  
  68. Решение с тернарен оператор:
  69.  
  70. function schoolCamp(input) {
  71.     let season = input[0];
  72.     let group = input[1];
  73.     let people = Number(input[2]);
  74.     let nights = Number(input[3]);
  75.     let price = 0;
  76.     let sport = '';
  77.  
  78.     if (season === 'Winter') {
  79.         price = group === 'boys' ? 9.60 : group === 'girls' ? 9.60 : 10.00;
  80.         sport = group === 'boys' ? 'Judo' : group === 'girls' ? 'Gymnastics' : 'Ski';
  81.     } else if (season === 'Spring') {
  82.         price = group === 'boys' ? 7.20 : group === 'girls' ? 7.20 : 9.50;
  83.         sport = group === 'boys' ? 'Tennis' : group === 'girls' ? 'Athletics' : 'Cycling';
  84.     } else {
  85.         price = group === 'boys' ? 15.00 : group === 'girls' ? 15.00 : 20.00;
  86.         sport = group === 'boys' ? 'Football' : group === 'girls' ? 'Volleyball' : 'Swimming';
  87.     }
  88.  
  89.     price *=
  90.         people >= 50 ? 0.50 :
  91.             people >= 20 ? 0.85 :
  92.                 people >= 10 ? 0.95 : 1;
  93.  
  94.     let total = price * people * nights;
  95.     console.log(`${sport} ${total.toFixed(2)} lv.`);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement