TaxCollector and Calculator

Feb 20th, 2022
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function taxCollectorRevenueAgency ( stringArrVehicles ){
2.
3.
4.     let carTaxes = 0;
5.     let carsArrLine = stringArrVehicles[0].split('>>');
6.     // console.log(carsArrLine);
7.     let collectedTaxes = 0;
8.
9.
10.     for (let index = 0; index < carsArrLine.length; index++) {
11.         let tokens = carsArrLine[index].split(" ");
12.         //console.log(tokens);
13.         let cartype = tokens[0];
14.        // console.log(cartype);
15.         let yearsInUseOfCar = Number(tokens[1]);
16.         //console.log(yearsInUseOfCar);
17.         let kmtravelled = Number(tokens[2]);
18.        // console.log(kmtravelled);
19.
20.
21.         if (cartype == "family"){
22.             let num = Math.trunc( kmtravelled / 3000);
23.             carTaxes = (num * 12) + (50 - (yearsInUseOfCar * 5));
24.             collectedTaxes += carTaxes;
25.             console.log(`A \${cartype} car will pay \${carTaxes.toFixed(2)} euros in taxes.`);
26.         } else if ( cartype == "heavyDuty" ) {
27.             let num = Math.trunc(kmtravelled / 9000);
28.             carTaxes = num * 14 + (80 - (yearsInUseOfCar * 8));
29.             collectedTaxes += carTaxes;
30.             console.log(`A \${cartype} car will pay \${carTaxes.toFixed(2)} euros in taxes.`);
31.         }  else if ( cartype == "sports"){
32.             let num = Math.trunc(kmtravelled / 2000);
33.             carTaxes = num * 18 + (100 - (yearsInUseOfCar * 9));
34.             collectedTaxes += carTaxes;
35.            console.log(`A \${cartype} car will pay \${carTaxes.toFixed(2)} euros in taxes.`);
36.         } else {
37.             console.log("Invalid car type.");
38.         }
39.
40.     }
41.      console.log(`The National Revenue Agency will collect \${collectedTaxes.toFixed(2)} euros in taxes.`);
42. }
43.
44.
45. taxCollectorRevenueAgency((['family 3 7210>>van 4 2345>>heavyDuty 9 31000>>sports 4 7410' ]));
46.