Advertisement
vladovip

Javascript - Vacation task -Exercise

Dec 15th, 2021
1,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(groupNumber, peopleType, dayOfWeek) {
  2.  
  3.     let totalPrice = 0;
  4.  
  5.     if (dayOfWeek == "Friday") {
  6.  
  7.         switch (peopleType) {
  8.             case "Students": if (groupNumber >= 30) {
  9.                 totalPrice = (groupNumber * 8.45) * 0.85;
  10.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  11.             } else {
  12.                 totalPrice = groupNumber * 8.45;
  13.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  14.             }
  15.                 break;
  16.  
  17.             case "Business": if (groupNumber >= 100) {
  18.                 totalPrice = (groupNumber - 10) * 10.90;
  19.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  20.             } else {
  21.                 totalPrice = groupNumber * 10.90;
  22.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  23.             }
  24.                 break;
  25.  
  26.             case "Regular": if (10 <= groupNumber && groupNumber <= 20) {
  27.                 totalPrice = (groupNumber * 15) * 0.95;
  28.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  29.             } else {
  30.                 totalPrice = groupNumber * 15;
  31.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  32.             }
  33.                 break;
  34.  
  35.             default: break;
  36.         }
  37.     } else if (dayOfWeek == "Saturday") {
  38.  
  39.         switch (peopleType) {
  40.             case "Students": if (groupNumber >= 30) {
  41.                 totalPrice = (groupNumber * 9.80) * 0.85;
  42.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  43.             } else {
  44.                 totalPrice = groupNumber * 9.80;
  45.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  46.             }
  47.                 break;
  48.  
  49.             case "Business": if (groupNumber >= 100) {
  50.                 totalPrice = (groupNumber - 10) * 15.60;
  51.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  52.             } else {
  53.                 totalPrice = groupNumber * 15.60;
  54.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  55.             }
  56.                 break;
  57.  
  58.             case "Regular": if (10 <= groupNumber && groupNumber <= 20) {
  59.                 totalPrice = (groupNumber * 20) * 0.95;
  60.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  61.             } else {
  62.                 totalPrice = groupNumber * 20;
  63.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  64.             }
  65.                 break;
  66.  
  67.             default: break;
  68.         }
  69.  
  70.     } else if (dayOfWeek == "Sunday") {
  71.  
  72.         switch (peopleType) {
  73.             case "Students": if (groupNumber >= 30) {
  74.                 totalPrice = (groupNumber * 10.46) * 0.85;
  75.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  76.             } else {
  77.                 totalPrice = groupNumber * 10.46;
  78.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  79.             }
  80.                 break;
  81.  
  82.             case "Business": if (groupNumber >= 100) {
  83.                 totalPrice = (groupNumber - 10) * 16;
  84.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  85.             } else {
  86.                 totalPrice = groupNumber * 16;
  87.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  88.             }
  89.                 break;
  90.  
  91.             case "Regular": if (10 <= groupNumber && groupNumber <= 20) {
  92.                 totalPrice = (groupNumber * 22.50) * 0.95;
  93.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  94.             } else {
  95.                 totalPrice = groupNumber * 22.50;
  96.                 console.log(`Total price: ${totalPrice.toFixed(2)}`);
  97.             }
  98.                 break;
  99.  
  100.             default: break;
  101.         }
  102.     }
  103. }
  104. solve(40, "Regular", "Saturday");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement