Advertisement
AlexandrP

courier

Dec 14th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function courierExpress(input) {
  2.     let weight = parseFloat(input[0]);
  3.     let typeCourier = input[1];
  4.     let distance = parseInt(input[2]);
  5.  
  6.     let allPrice = 0.0;
  7.  
  8.     if (typeCourier === "standard") {
  9.       if (weight < 1) {
  10.         allPrice = distance * 0.03;
  11.       } else if (weight >= 1 && weight <= 10) {
  12.         allPrice = distance * 0.05;
  13.       } else if (weight >= 11 && weight <= 40) {
  14.         allPrice = distance * 0.10;
  15.       } else if (weight >= 41 && weight <= 90) {
  16.         allPrice = distance * 0.15;
  17.       } else if (weight >= 91 && weight <= 150) {
  18.         allPrice = distance * 0.20;
  19.       }
  20.     } else if (typeCourier === "express") {
  21.       if (weight < 1) {
  22.         allPrice = distance * 0.03 + 0.03 * 0.8 * weight * distance;
  23.       } else if (weight >= 1 && weight <= 10) {
  24.         allPrice = distance * 0.05 + 0.05 * 0.4 * weight * distance;
  25.       } else if (weight >= 11 && weight <= 40) {
  26.         allPrice = distance * 0.10 + 0.10 * 0.05 * weight * distance;
  27.       } else if (weight >= 41 && weight <= 90) {
  28.         allPrice = distance * 0.15 + 0.15 * 0.02 * weight * distance;
  29.       } else if (weight >= 91 && weight <= 150) {
  30.         allPrice = distance * 0.20 + 0.20 * 0.01 * weight * distance;
  31.       }
  32.     }
  33.  
  34.     const output = `The delivery of your shipment with weight of ${weight.toFixed(
  35.       3
  36.     )} kg. would cost ${allPrice.toFixed(2)} lv.`;
  37.  
  38.     console.log(output);
  39.   }
  40.   courierExpress(["87", "express","130"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement