TZinovieva

Fruit Shop 100/100

May 20th, 2022 (edited)
62
0
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 day = input[1];
  4.     let quantity = input[2];
  5.  
  6.         let price = 0;
  7.         if (day == "Monday" || day == "Tuesday" || day == "Wednesday"
  8.         || day == "Thursday" || day == "Friday") {
  9.             switch (fruit) {
  10.                 case "banana":
  11.                     price = quantity * 2.50;
  12.                     console.log(price.toFixed(2));
  13.                     break;
  14.                 case "apple":
  15.                     price = quantity * 1.20;
  16.                     console.log(price.toFixed(2));
  17.                     break;
  18.                 case "orange":
  19.                     price = quantity * 0.85;
  20.                     console.log(price.toFixed(2));
  21.                     break;
  22.                 case "grapefruit":
  23.                     price = quantity * 1.45;
  24.                     console.log(price.toFixed(2));
  25.                     break;
  26.                 case "kiwi":
  27.                     price = quantity * 2.70;
  28.                     console.log(price.toFixed(2));
  29.                     break;
  30.                 case "pineapple":
  31.                     price = quantity * 5.50;
  32.                     console.log(price.toFixed(2));
  33.                     break;
  34.                 case "grapes":
  35.                     price = quantity * 3.85;
  36.                     console.log(price.toFixed(2));
  37.                     break;
  38.                     default:
  39.                         console.log("error");
  40.                         break;
  41.             }
  42.             } else if (day == "Saturday" || day == "Sunday") {
  43.                 switch (fruit) {
  44.                     case "banana":
  45.                         price = quantity * 2.70;
  46.                         console.log(price.toFixed(2));
  47.                         break;
  48.                     case "apple":
  49.                         price = quantity * 1.25;
  50.                         console.log(price.toFixed(2));
  51.                         break;
  52.                     case "orange":
  53.                         price = quantity * 0.90;
  54.                         console.log(price.toFixed(2));
  55.                         break;
  56.                     case "grapefruit":
  57.                         price = quantity * 1.60;
  58.                         console.log(price.toFixed(2));
  59.                         break;
  60.                     case "kiwi":
  61.                         price = quantity * 3.00;
  62.                         console.log(price.toFixed(2));
  63.                         break;
  64.                     case "pineapple":
  65.                         price = quantity * 5.60;
  66.                         console.log(price.toFixed(2));
  67.                         break;
  68.                     case "grapes":
  69.                         price = quantity * 4.20;
  70.                         console.log(price.toFixed(2));
  71.                         break;  
  72.                         default:
  73.                             console.log("error");
  74.                             break;      
  75.                 }
  76.         } else {
  77.             console.log("error");
  78.         }
  79.     }
Add Comment
Please, Sign In to add comment