I have the following code to find out the profit after tax.
var amount = 500;
var profit = 0;
var period = 24;
var invest = amount * period;
var totalamount = 0;
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const calculate = () => {
rl.question("what is your annual income: ", function (income) {
for (var i = 1; i <= period; i++) {
profit = amount * 0.1;
totalamount = amount + profit;
if (i === 12) {
totalamount = totalamount + income;
if (totalamount > 18200 && totalamount < 45000) {
totalamount = totalamount - 0.19 * (totalamount - 18200);
} else if (totalamount > 45000 && totalamount < 120000) {
totalamount = totalamount - (0.325 * (totalamount - 45000) + 10184);
} else if (totalamount > 120000 && totalamount < 180000) {
totalamount = totalamount - (0.37 * (totalamount - 120000) + 64026);
} else if (totalamount > 180000) {
totalamount = totalamount - (0.45 * (totalamount - 180000) + 86226);
}
console.log(i);
}
amount = totalamount + 500;
}
var numb = totalamount.toFixed(2);
console.log(numb);
console.log(invest);
});
};
calculate();
When I run this code I’m getting the error, ‘TypeError: totalamount.toFixed is not a function’. also when I change the period to 24 to check for 2 years and console.log(totalamount) getting a value with such large number of decimal points. Not sure why and what that means and would appreciate if someone could help me out. I’m not sure how to call the value with large points so couldnt google it either. The value with large decimal points I’m talking about is this:
11761.35607196549810005001176.13560719655500NaN500NaN500NaN500NaN500NaN500NaN500NaN500NaN500NaN500NaN500NaN