Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.5 kB
1
Indexable
Never
function commissions(input) {

  let city = (input[0]);
  let sales = Number(input[1]); 
  let error = false;
  let finalCommisssion = 0; 
  
  if (sales >= 0 && sales <= 500) {
      switch (city) {
          case "Sofia": finalCommisssion = sales * 0.05; break; 
          case "Varna": finalCommisssion = sales * 0.045; break; 
          case "Plovdiv": finalCommisssion = sales * 0.055; break;
          default: error = true;
      }
  } else if (sales > 500 && sales <= 1000) {
      switch (city) {
          case "Sofia": finalCommisssion = sales * 0.07; break; 
          case "Varna": finalCommisssion = sales * 0.075; break; 
          case "Plovdiv": finalCommisssion = sales * 0.08; break;
          default: error = true;
      }
  } else if (sales > 1000 && sales <= 10000) {
      switch (city) {
          case "Sofia": finalCommisssion = sales * 0.08; break; 
          case "Varna": finalCommisssion = sales * 0.1; break; 
          case "Plovdiv": finalCommisssion = sales * 0.12; break;
          default: error = true;
      }
  } else if (sales > 10000) {
      switch (city) {
          case "Sofia": finalCommisssion = sales * 0.12; break; 
          case "Varna": finalCommisssion = sales * 0.13; break; 
          case "Plovdiv": finalCommisssion = sales * 0.145; break; 
          default: error = true;
      }
  }  else {
    error = true;
  }
  if (!error)
  console.log(finalCommisssion.toFixed(2))
  else 
  console.log("error")
  }
Leave a Comment