Advertisement
Spocoman

05. Vacation

Dec 22nd, 2021 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function vacantion(input) {
  2.     let budget = Number(input[0]);
  3.     let season = input[1];
  4.     let location = '';
  5.     let place = '';
  6.  
  7.     if (season === 'Summer') {
  8.         location = 'Alaska';
  9.     } else {
  10.         location = 'Morocco';
  11.     }
  12.  
  13.     if (budget > 3000) {
  14.         place = 'Hotel';
  15.         budget *= 0.9;
  16.     } else if (budget > 1000) {
  17.         if (season === 'Summer') {
  18.             budget *= 0.8;
  19.         } else {
  20.             budget *= 0.6;
  21.         }
  22.         place = 'Hut';
  23.     } else if (budget > 0) {
  24.         if (season === 'Summer') {
  25.             budget *= 0.65;
  26.         } else {
  27.             budget *= 0.45;
  28.         }
  29.         place = 'Camp';
  30.     }
  31.     console.log(`${location} - ${place} - ${budget.toFixed(2)}`);
  32. }
  33.  
  34. Решение с тернарен оператор:
  35.  
  36. function vacantion(input) {
  37.     let budget = Number(input[0]);
  38.     let season = input[1];
  39.  
  40.     let location = season === 'Summer' ? 'Alaska' : 'Morocco';
  41.  
  42.     let place =
  43.         budget > 3000 ? 'Hotel' :
  44.         budget > 1000 ? 'Hut' : 'Camp';
  45.  
  46.     budget *=
  47.         budget > 3000 ? 0.9 :
  48.         budget > 1000 ? (season === 'Summer' ? 0.8 : 0.6) :
  49.         (season === 'Summer' ? 0.65 : 0.45);
  50.  
  51.     console.log(`${location} - ${place} - ${budget.toFixed(2)}`);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement