gskorchev

fruits

Jan 28th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fruits(input) {
  2.     let fruit = input.shift();
  3.     let day = input.shift();
  4.     let quantity = Number(input.shift());
  5.     let price = 0;
  6.     switch (day) {
  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.00;
  40.             } else if (fruit == "pineapple") {
  41.                 price = quantity * 5.60;
  42.             } else if (fruit == "grapes") {
  43.                 price = quantity * 4.20;
  44.             };
  45.             break;
  46.         default:
  47.             price = 0;
  48.     }
  49.     if (price == 0) {
  50.         console.log("error");
  51.     } else {
  52.         console.log(price.toFixed(2));
  53.     }
  54. }
  55.  
  56. fruits(["orange", "Friday", 0.6]);
Advertisement
Add Comment
Please, Sign In to add comment