# javascript – Build a stamp duty calculator for various types of buyers

I had a task where I had to build a stamp duty calculator, which calculates the tax or stamp duty first-time buyers(`ftb`) returning buyers (`rtb`), and second-home buyers (`shb`) had to pay when purchasing the home.

These were the tax bands, although I think some of the percentages may be slightly wrong.

``````First Time Buyers
0 to £300,000 - 0%
£300,001 to £925,000 - 5%
£925001 to £1,500,000 - 10%
£1,500,000 and above - 12%

0 to £125,000 - 0%
£125,001 to £250,000 - 2%
£250,001 to £925,000 - 5%
£925,001 to £1,500,000 - 10%
£1,500,000 and above - 12%

0 to £125,000 - 3%
£125,001 to £250,000 - 5%
£250,001 to £925,000 - 8%
£925,001 to £1,500,000 - 13%
£1,500,000 and above - 15%
``````

Here is my solution, I look forward to the feedback.

``````const stampDutyCalc = (price) => {
let stampdutyObject = {
ftb: 0,
rtb: 0,
shb: 0,
};

return stampdutyObject;
};

if (price <= 300000) {
stampdutyObject.ftb += 0;
} else if (price > 300000 && price <= 925000) {
stampdutyObject.ftb += price * 0.05;
} else if (price > 925000 && price <= 1500000) {
stampdutyObject.ftb += (price - 925000) * 0.1 + (925000 - 300000) * 0.05;
} else {
stampdutyObject.ftb +=
(price - 1500000) * 0.12 +
(1500000 - 925000) * 0.1 +
(925000 - 300000) * 0.05;
}
}

if (price <= 125000) {
stampdutyObject.rtb += 0;
} else if (price > 125000 && price <= 250000) {
stampdutyObject.rtb += price * 0.02;
} else if (price > 250000 && price <= 925000) {
stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
} else if (price > 925000 && price <= 1500000) {
stampdutyObject.rtb +=
(price - 925000) * 0.1 +
(925000 - 250000) * 0.05 +
(250000 - 125000) * 0.02;
} else {
stampdutyObject.rtb +=
(price - 1500000) * 0.12 +
(1500000 - 925000) * 0.1 +
(925000 - 250000) * 0.05 +
(250000 - 125000) * 0.02;
}
}

if (price <= 125000) {
stampdutyObject.shb = price * 0.03;
} else if (price > 125000 && price <= 250000) {
stampdutyObject.shb += (price - 125000) * 0.05 + 125000 * 0.03;
} else if (price > 250000 && price <= 925000) {
stampdutyObject.shb +=
(price - 250000) * 0.08 + (250000 - 125000) * 0.05 + 125000 * 0.03;
} else if (price > 925000 && price <= 1500000) {
stampdutyObject.shb +=
(price - 925000) * 0.13 +
(925000 - 250000) * 0.08 +
(250000 - 125000) * 0.05 +
125000 * 0.03;
} else {
stampdutyObject.shb +=
(price - 1500000) * 0.15 +
(1500000 - 925000) * 0.13 +
(925000 - 250000) * 0.08 +
(250000 - 125000) * 0.0 +
125000 * 0.03;
}
}

if (price <= 125000) {
stampdutyObject.rtb += 0;
} else if (price > 125000 && price <= 250000) {
stampdutyObject.rtb += price * 0.02;
} else if (price > 250000 && price <= 925000) {
stampdutyObject.rtb += (price - 250000) * 0.05 + (250000 - 125000) * 0.02;
} else if (price > 925000 && price <= 1500000) {
stampdutyObject.rtb +=
(price - 925000) * 0.1 +
(925000 - 250000) * 0.05 +
(250000 - 125000) * 0.02;
} else {
stampdutyObject.rtb +=
(price - 1500000) * 0.12 +
(1500000 - 925000) * 0.1 +
(925000 - 250000) * 0.05 +
(250000 - 125000) * 0.02;
}
}
``````