Advertisement
vborislavova

08. Fruit Shop - Conditional Statements Advanced

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