I'm writing a function to calculate the income tax burden in the UK, and the Google Apps Script page keeps giving me an error notice that there's a missing semicolon (Missing ; before statement. (line 27, file "Code")). This code runs fine in my browser's javscript console and I can't seem to find why AppScript doesn't like it. Does anyone know what I'm doing wrong?
function apply_reliefs(amount, reliefs) {
/**
* Make some logic here to decrease the taxable amount
*/
return amount;
};
function apply_allowances(amount, allowances) {
/**
* Make some logic here to decrease the taxable amount
*/
return amount;
};
/**
* Returns the taxes owed given the income earned for a year and the reliefs and allowances.
*
* @param {income} income The GROSS income for the year.
* @param {[allowances]} opt_allowances A string of alowances codes
* @param {[reliefs]} opt_reliefs A string of relief codes
* @return The taxes owed on the income earned.
* @customfunction
*/
function brittax(income, opt_allowances, opt_reliefs) {
// FYI: the next line is line 27:
let allowances = opt_allowances;
let reliefs = opt_reliefs;
if(null == allowances) {
allowances = "";
}
if(null == reliefs) {
reliefs = "";
}
let amount = apply_reliefs(income, reliefs);
amount = apply_allowances(amount, allowances);
// Band Taxable income Tax rate
// Personal Allowance Up to £12,500 0%
// Basic rate £12,501 to £50,000 20%
// Higher rate £50,001 to £150,000 40%
// Additional rate over £150,000 45%
let brackets = [
{ limit: 12500, rate: 0 },
{ limit: 50000, rate: 0.2},
{ limit: 150000, rate: 0.4},
{ limit: null, rate: 0.45}
];
let tax = 0;
for (const bracket of brackets) {
if(null == bracket.limit) {
tax += amount * bracket.rate;
} else {
tax += Math.min(bracket.limit, amount) * bracket.rate;
amount -= bracket.limit;
}
if(amount <= 0) {
break;
}
}
return tax;
};