Advertisement
ckeuta

Untitled

Feb 28th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let fruit = input.shift();
  4. let day = input.shift();
  5. let count = Number(input.shift());
  6.  
  7. let weekDay = false;
  8. let weekEnd = false;
  9. let isError
  10. let price = Number;
  11.  
  12.  
  13. if (day === 'monday' || day === 'tuesday' || day === 'wednesday' || day === 'thursday' || day === 'friday') {
  14.  
  15. weekDay = true;
  16.  
  17. }
  18.  
  19. if (day === 'saturday' || day === 'sunday') {
  20.  
  21. weekEnd = true;
  22. }
  23.  
  24. if (weekEnd === false && weekDay === false) {
  25.  
  26. isError = true;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. switch (fruit) {
  34. case 'banana':
  35. if (weekDay === true) {
  36. price = 2.50;
  37. console.log((price * count).toFixed(2))
  38.  
  39. } if (weekEnd === true) {
  40. price = 2.70
  41. console.log((price * count).toFixed(2))
  42. }
  43.  
  44. break;
  45.  
  46. case 'apple':
  47. if (weekDay === true) {
  48.  
  49. price = 1.20
  50. console.log((price * count).toFixed(2))
  51. } if (weekEnd === true) {
  52.  
  53. price = 1.25
  54. console.log((price * count).toFixed(2))
  55. }
  56. break;
  57.  
  58. case 'orange':
  59. if (weekDay === true) {
  60.  
  61. price = 0.85
  62. console.log((price * count).toFixed(2))
  63. } if (weekEnd === true) {
  64.  
  65. price = 0.90
  66. console.log((price * count).toFixed(2))
  67. }
  68.  
  69. break;
  70.  
  71. case 'grapefruit':
  72. if (weekDay === true) {
  73.  
  74. price = 1.45
  75. console.log((price * count).toFixed(2))
  76. } if (weekEnd === true) {
  77.  
  78. price = 1.60
  79. console.log((price * count).toFixed(2))
  80. }
  81.  
  82. break;
  83.  
  84. case 'kiwi':
  85. if (weekDay === true) {
  86.  
  87. price = 2.70
  88. console.log((price * count).toFixed(2))
  89. } if (weekEnd === true) {
  90.  
  91. price = 3.00
  92. console.log((price * count).toFixed(2))
  93. }
  94.  
  95. break;
  96.  
  97. case 'grape':
  98. if (weekDay === true) {
  99.  
  100. price = 3.85
  101. console.log((price * count).toFixed(2))
  102. } if (weekEnd === true) {
  103.  
  104. price = 4.20
  105. console.log((price * count).toFixed(2))
  106. }
  107.  
  108. break;
  109.  
  110. case 'pineapple':
  111. if (weekDay === true) {
  112. price = 5.50
  113. console.log((price * count).toFixed(2))
  114.  
  115. } if (weekEnd === true) {
  116.  
  117. price = 5.60
  118. console.log((price * count).toFixed(2))
  119. }
  120.  
  121. break;
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128. }
  129.  
  130. solve ([ 'orange', 'sunday', '3'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement