ProdanTenev

fruitShop

Feb 12th, 2022 (edited)
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.93 KB | None | 0 0
  1. function fruitShop(input) {
  2.     let fruit = String(input[0]);
  3.     let day = String(input[1]);
  4.     let quantity = Number(input[2]);
  5.     let sum;
  6.     // плод (banana / apple / orange / grapefruit / kiwi / pineapple / grapes)
  7.     // ден от седмицата (Monday / Tuesday / Wednesday / Thursday / Friday / Saturday / Sunday)
  8.     if (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday" || day == "Friday") {
  9.             switch (fruit) {
  10.                 case "banana":
  11.                     sum = quantity * 2.5;
  12.                     console.log(sum.toFixed(2));
  13.                     break;
  14.                 case "apple":
  15.                     sum = quantity * 1.2;
  16.                     console.log(sum.toFixed(2));
  17.                     break;
  18.                 case "orange":
  19.                     sum = quantity * 0.85;
  20.                     console.log(sum.toFixed(2));
  21.                     break;
  22.                 case "grapefruit":
  23.                     sum = quantity * 1.45;
  24.                     console.log(sum.toFixed(2));
  25.                     break;
  26.                 case "kiwi":
  27.                     sum = quantity * 2.70;
  28.                     console.log(sum.toFixed(2));
  29.                     break;
  30.                 case "pineapple":
  31.                     sum = quantity * 5.50;
  32.                     console.log(sum.toFixed(2));
  33.                     break;
  34.                 case "grapes":
  35.                     sum = quantity * 3.85;
  36.                     console.log(sum.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.                     sum = quantity * 2.7;
  46.                     console.log(sum.toFixed(2));
  47.                     break;
  48.                 case "apple":
  49.                     sum = quantity * 1.25;
  50.                     console.log(sum.toFixed(2));
  51.                     break;
  52.                 case "orange":
  53.                     sum = quantity * 0.9;
  54.                     console.log(sum.toFixed(2));
  55.                     break;
  56.                 case "grapefruit":
  57.                     sum = quantity * 1.6;
  58.                     console.log(sum.toFixed(2));
  59.                     break;
  60.                 case "kiwi":
  61.                     sum = quantity * 3;
  62.                     console.log(sum.toFixed(2));
  63.                     break;
  64.                 case "pineapple":
  65.                     sum = quantity * 5.60;
  66.                     console.log(sum.toFixed(2));
  67.                     break;
  68.                 case "grapes":
  69.                     sum = quantity * 4.2;
  70.                     console.log(sum.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