vikkktor

fruitShop

May 24th, 2021 (edited)
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fruitShop(input) {
  2.     let fruit = input[0];
  3.     let weekday = input[1];
  4.     let quantity = Number(input[2]);
  5.     let price = Number(input[3]);
  6.     switch (weekday) {
  7.         case "Monday":
  8.         case "Tuesday":
  9.         case "Wednesday":
  10.         case "Thursday":
  11.         case "Friday":
  12.             if (fruit === "banana") {
  13.                 price = quantity * 2.50;
  14.             } else if (fruit === "apple") {
  15.                 price = quantity * 1.20;
  16.             } else if (fruit === "orange") {
  17.                 price = quantity * 0.85;
  18.             } else if (fruit === "grapefruit") {
  19.                 price = quantity * 1.45;
  20.             } else if (fruit === "kiwi") {
  21.                 price = quantity * 2.70;
  22.             } else if (fruit === "pineapple") {
  23.                 price = quantity * 5.50;
  24.             } else if (fruit === "grapes") {
  25.                 price = quantity * 3.85;
  26.             }
  27.             break;
  28.         case "Saturday":
  29.         case "Sunday":
  30.             if (fruit === "banana") {
  31.                 price = quantity * 2.70;
  32.             } else if (fruit === "apple") {
  33.                 price = quantity * 1.25;
  34.             } else if (fruit === "orange") {
  35.                 price = quantity * 0.90;
  36.             } else if (fruit === "grapefruit") {
  37.                 price = quantity * 1.60;
  38.             } else if (fruit === "kiwi") {
  39.                 price = quantity * 3;
  40.             } else if (fruit === "pineapple") {
  41.                 price = quantity * 5.60;
  42.             } else if (fruit === "grapes") {
  43.                 price = quantity * 4.20;
  44.             }
  45.             break;
  46.     }
  47.     if (weekday != weekday) {
  48.  
  49.     } else if (fruit !== fruit) {
  50.         console.log(error);
  51.     }
  52.  
  53.     console.log(price.toFixed(2));
  54.  
  55. }
  56. fruitShop(["orange",
  57. "Sunday",
  58. "3"])
RAW Paste Data