didkoslawow

Untitled

Sep 26th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. function fruitShop(input) {
  2.  
  3. let fruit = input[0];
  4. let weekDay = input[1];
  5. let fruitQty = Number(input[2]);
  6. let totalPrice = 0;
  7.  
  8. switch (weekDay) {
  9. case "Monday":
  10. case "Tuesday":
  11. case "Wednesday":
  12. case "Thursday":
  13. case "Friday":
  14. if (fruit === "banana") {
  15. totalPrice = fruitQty * 2.50;
  16. } else if (fruit === "apple") {
  17. totalPrice = fruitQty * 1.20;
  18. } else if (fruit === "orange") {
  19. totalPrice = fruitQty * 0.85;
  20. } else if (fruit === "grapefruit") {
  21. totalPrice = fruitQty * 1.45;
  22. } else if (fruit === "kiwi") {
  23. totalPrice = fruitQty * 2.70;
  24. } else if (fruit === "pineapple") {
  25. totalPrice = fruitQty * 5.50;
  26. } else if (fruit === "grapes") {
  27. totalPrice = fruitQty * 3.85;
  28. }
  29. break;
  30. case "Saturday":
  31. case "Sunday":
  32. if (fruit === "banana") {
  33. totalPrice = fruitQty * 2.70;
  34. } else if (fruit === "apple") {
  35. totalPrice = fruitQty * 1.25;
  36. } else if (fruit === "orange") {
  37. totalPrice = fruitQty * 0.90;
  38. } else if (fruit === "grapefruit") {
  39. totalPrice = fruitQty * 1.60;
  40. } else if (fruit === "kiwi") {
  41. totalPrice = fruitQty * 3.00;
  42. } else if (fruit === "pineapple") {
  43. totalPrice = fruitQty * 5.60;
  44. } else if (fruit === "grapes") {
  45. totalPrice = fruitQty * 4.20;
  46. }
  47. break;
  48. }
  49.  
  50.  
  51.  
  52.  
  53. if ((weekDay !== "Monday" && weekDay !== "Tuesday" && weekDay !== "Wednesday" && weekDay !== "Thursday" && weekDay !== "Friday" && weekDay !== "Saturday" && weekDay !== "Sunday") && (fruit !== "banana" && fruit !== "apple" && fruit !== "orange" && fruit !== "grapefruit" && fruit !== "kiwi" && fruit !== "pineaplle" && fruit !== "grapes")) {
  54. console.log("error");
  55. } else {
  56. console.log(totalPrice.toFixed(2));
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment