PavelIvanov

Untitled

May 31st, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. function solve(input) {
  2. let index = 0;
  3. let town = input[index++];
  4. let packet = input[index++];
  5. let vip = input[index++];
  6. let days = +input[index++];
  7. if (days >= 8) {
  8. days -= 1;
  9. }
  10. let sum = days * 1;
  11. let count = 0;
  12. let invalid = true;
  13. if (town == 'Bansko' || town == 'Borovets') {
  14. if (vip == 'yes') {
  15. switch (packet) {
  16. case "withEquipment":
  17. sum *= 100 * 0.9;
  18. break;
  19. case "noEquipment":
  20. sum *= 80 * 0.95;
  21. break;
  22. } count++;
  23. } else {
  24. switch (packet) {
  25. case "withEquipment":
  26. sum *= 100;
  27. break;
  28. case "noEquipment":
  29. sum *= 80;
  30. break;
  31. }
  32. } count++;
  33.  
  34.  
  35. } else if (town == 'Varna' || town == 'Burgas') {
  36. if (vip == 'yes') {
  37. switch (packet) {
  38. case "withBreakfast":
  39. sum *= 130 * 0.88;
  40. break;
  41. case "noBreakfast":
  42. sum *= 100 * 0.93;
  43. break;
  44. }count++;
  45. } else {
  46. switch (packet) {
  47. case "withBreakfast":
  48. sum *= 130;
  49. break;
  50. case "noBreakfast":
  51. sum *= 100;
  52. break;
  53. }count++;
  54. }
  55. } else {
  56. console.log("Invalid input!");
  57. invalid = false;
  58.  
  59. }
  60.  
  61.  
  62.  
  63. if (days < 1) {
  64. console.log("Days must be positive number!");
  65. } else if (invalid) {
  66. console.log(`The price is ${sum.toFixed(2)}lv! Have a nice time!`);
  67. }
  68. }
  69.  
  70. solve(['Gabrovo', 'noBreakfast', 'no', '3'])
Add Comment
Please, Sign In to add comment