Advertisement
Spocoman

Courier Express

Jan 8th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function courierExpress(input) {
  2.     let weight = Number(input[0]);
  3.     let service = input[1];
  4.     let distance = Number(input[2]);
  5.  
  6.     let kmPrice = 0;
  7.  
  8.     if (weight < 1) {
  9.         kmPrice = 0.03;
  10.     } else if (weight >= 1 && weight < 10) {
  11.         kmPrice = 0.05;
  12.     } else if (weight >= 10 && weight < 40) {
  13.         kmPrice = 0.1;
  14.     } else if (weight >= 40 && weight < 90) {
  15.         kmPrice = 0.15;
  16.     } else if (weight >= 90 && weight < 150) {
  17.         kmPrice = 0.2;
  18.     }
  19.  
  20.     let express = 0;
  21.  
  22.     if (service === "express") {
  23.         if (weight < 1) {
  24.             express = kmPrice / 100 * 80;
  25.         } else if (weight >= 1 && weight < 10) {
  26.             express = kmPrice / 100 * 40;
  27.         } else if (weight >= 10 && weight < 40) {
  28.             express = kmPrice / 100 * 5;
  29.         } else if (weight >= 40 && weight < 90) {
  30.             express = kmPrice / 100 * 2;
  31.         } else if (weight >= 90 && weight < 150) {
  32.             express = kmPrice / 100;
  33.         }
  34.     }
  35.     let total = kmPrice * distance + express * weight * distance;
  36.     console.log(`The delivery of your shipment with weight of ${weight.toFixed(3)} kg. would cost ${total.toFixed(2)} lv.`);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement