svephoto

Trade Commissions [JavaScript]

May 18th, 2021
809
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tradeCommissions(input) {
  2.     let city = input[0];
  3.     let sales = Number(input[1]);
  4.     let commission = 0.0;
  5.    
  6.     if (city == 'Sofia') {
  7.         if (sales >= 0 && sales <= 500) {
  8.             commission = sales * 0.05;
  9.         } else if (sales > 500 && sales <= 1000) {
  10.             commission = sales * 0.07;
  11.         } else if (sales > 1000 && sales <= 10000) {
  12.             commission = sales * 0.08;
  13.         } else {
  14.             commission = sales * 0.12;
  15.         }
  16.     } else if (city == 'Varna') {
  17.         if (sales >= 0 && sales <= 500) {
  18.             commission = sales * 0.045;
  19.         } else if (sales > 500 && sales <= 1000) {
  20.             commission = sales * 0.075;
  21.         } else if (sales > 1000 && sales <= 10000) {
  22.             commission = sales * 0.10;
  23.         } else {
  24.             commission = sales * 0.13;
  25.         }
  26.     } else if (city == 'Plovdiv') {
  27.         if (sales >= 0 && sales <= 500) {
  28.             commission = sales * 0.055;
  29.         } else if (sales > 500 && sales <= 1000) {
  30.             commission = sales * 0.08;
  31.         } else if (sales > 1000 && sales <= 10000) {
  32.             commission = sales * 0.12;
  33.         } else {
  34.             commission = sales * 0.145;
  35.         }
  36.     }
  37.  
  38.     if (commission > 0) {
  39.         console.log(commission.toFixed(2));
  40.     } else {
  41.         console.log('error');
  42.     }
  43. }
  44.  
RAW Paste Data