Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
3
Indexable
Never
function TradeCommissions(input) {
    let city = input[0];
    let sales = Number(input[1]);
    let tradeCommissions = 0;
  let error = false;
    if (sales >= 0 && sales <= 500) {
        switch (city) {
            case 'Sofia': tradeCommissions = sales * 0.05; break;
            case 'Varna': tradeCommissions = sales * 0.045; break;
            case 'Plovdiv': tradeCommissions = sales * 0.055; break;
            default: console.log('error'); break;
        }
    } else if (sales >= 500 && sales <= 1000) {
        switch (city) {
            case 'Sofia': tradeCommissions = sales * 0.07; break;
            case 'Varna': tradeCommissions = sales * 0.075; break;
            case 'Plovdiv': tradeCommissions = sales * 0.08; break;
            default: console.log('error'); error = true; break;
        }
    } else if (sales >= 1000 && sales <= 10000) {
        switch (city) {
            case 'Sofia': tradeCommissions = sales * 0.08; break;
            case 'Varna': tradeCommissions = sales * 0.1; break;
            case 'Plovdiv': tradeCommissions = sales * 0.12; break;
            default: console.log('error');error = true; break;
        }
    } else if (sales > 10000) {
        switch (city) {
            case 'Sofia': tradeCommissions = sales * 0.12; break;
            case 'Varna': tradeCommissions = sales * 0.13; break;
            case 'Plovdiv': tradeCommissions = sales * 0.145; break;
            default: console.log('error');error = true; break;
        }
    
    }
        else {error = true;console.log('error');}
  if (error!=true){
       console.log(tradeCommissions.toFixed(2)); }
}
Leave a Comment