The tax rate is often a function of the income or in other words individuals at different income levels will pay different taxes.

Also, in some countries like the UK, individuals get to keep a certain amount of their income
that's not taxed while the remainder is taxed at the applicable rate. So for example, let's say a person makes 100K and their tax rate is 10% or 0.1 but they are allowed to keep 30K. They will end up paying 7000 or 7K in taxes because:
100K - 30K = 70K. // they keep 30K and have 70K left.
10% of 70K = 7K. // they will pay 10% tax on what's left.

Your challenge is to complete the code below to return the function that will correctly calculate taxes for a person based on the rules below.

Amount                            Tax Rate
<= 100,000                        10% or 0.1
> 100,000 to 500,000 (inclusive)  20% or 0.2
> 500,000                         35% or 0.3

// Should return a function that accepts a number that's the amount to be taxed
// and returns the tax amount after factoring in the income not taxed and the
// applicable tax rate.
function getTaxCalculator(incomeNotTaxed) {
 // your code here (approximately 10 lines)
   function calculateTax(amount){
   let taxAmount = amount - incomeNotTaxed;
    if (amount <= 100000){
        taxAmount * 0.1
    }else if((amount>100000) && (amount<= 500000)){
        taxAmount * 0.2
        taxAmount * 0.3 
 return calculateTax       

const calculateTax = getTaxCalculator(30000)
console.log(calculateTax(100000)) // should print 70000
console.log(calculateTax(350000)) // should print 64000
console.log(calculateTax(600000)) // should print 171000
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter