Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function courierExpress(input) {
- let weight = Number(input[0]);
- let service = input[1];
- let distance = Number(input[2]);
- let kmPrice = 0;
- if (weight < 1) {
- kmPrice = 0.03;
- } else if (weight >= 1 && weight < 10) {
- kmPrice = 0.05;
- } else if (weight >= 10 && weight < 40) {
- kmPrice = 0.1;
- } else if (weight >= 40 && weight < 90) {
- kmPrice = 0.15;
- } else if (weight >= 90 && weight < 150) {
- kmPrice = 0.2;
- }
- let express = 0;
- if (service === "express") {
- if (weight < 1) {
- express = kmPrice / 100 * 80;
- } else if (weight >= 1 && weight < 10) {
- express = kmPrice / 100 * 40;
- } else if (weight >= 10 && weight < 40) {
- express = kmPrice / 100 * 5;
- } else if (weight >= 40 && weight < 90) {
- express = kmPrice / 100 * 2;
- } else if (weight >= 90 && weight < 150) {
- express = kmPrice / 100;
- }
- }
- let total = kmPrice * distance + express * weight * distance;
- console.log(`The delivery of your shipment with weight of ${weight.toFixed(3)} kg. would cost ${total.toFixed(2)} lv.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement