After incorporating the suggestions I received, I have revised the entire code. However, there seems to be a missing element as I am still unable to utilize the var deducere in mathematical operations. I consistently receive NaN. Any advice or feedback on my code would be greatly appreciated, as I have reached a point where I am out of ideas. It appears that this process is indeed the most effective way to learn.
function calculateIncome() {
var gross_income = document.getElementById("venit_brut").value;
var selection = document.getElementById("select1").value;
var social_security = (10.5 / 100) * gross_income;
var health_insurance = (5.5 / 100) * gross_income;
var unemployment = (0.5 / 100) * gross_income;
var num_tickets = document.getElementById("nr_tichete").value;
var ticket_value = document.getElementById("val_tichete").value;
var tickets = num_tickets * ticket_value;
var tax = (16 / 100) * (income + tickets);
if (gross_income != null) {
document.getElementById("venit_brutx").innerHTML = Math.round(gross_income);
document.getElementById("cas").innerHTML = Math.round(social_security);
document.getElementById("cass").innerHTML = Math.round(health_insurance);
document.getElementById("somaj").innerHTML = Math.round(unemployment);
document.getElementById("venitx").innerHTML = Math.round(income);
document.getElementById("tichete").innerHTML = Math.round(tickets);
document.getElementById("impozit").innerHTML = Math.round(tax);
document.getElementById("venit_net").innerHTML = Math.round(net_income);
}
};
function calculateDeduction(selection, gross_income) {
var deduction0 = (1 - (gross_income - 1500) / 1500) * 300;
var deduction1 = (1 - (gross_income - 1500) / 1500) * 400;
var deduction2 = (1 - (gross_income - 1500) / 1500) * 500;
var deduction3 = (1 - (gross_income - 1500) / 1500) * 600;
var deduction4 = (1 - (gross_income - 1500) / 1500) * 800;
if (selection == 0 && gross_income <= 1500) {
return 300;
}
if (selection == 0 && gross_income > 1500 && gross_income <= 3000) {
return Math.ceil10(deduction0, 1);
}
if (selection == 1 && gross_income <= 1500) {
return 400;
}
if (selection == 1 && gross_income > 1500 && gross_income <= 3000) {
return Math.ceil10(deduction1, 1);
}
if (selection == 2 && gross_income <= 1500) {
return 500;
}
if (selection == 2 && gross_income > 1500 && gross_income <= 3000) {
return Math.ceil10(deduction2, 1);
}
if (selection == 3 && gross_income <= 1500) {
return 600;
}
if (selection == 3 && gross_income > 1500 && gross_income <= 3000) {
return Math.ceil10(deduction3, 1);
}
if (selection == 4 && gross_income <= 1500) {
return 800;
}
if (selection == 4 && gross_income > 1500 && gross_income <= 3000) {
return Math.ceil10(deduction4, 1);
}
if (document.getElementById("btn_deducere").checked == false) {
document.getElementById("deducerex").innerHTML = 0;
}
if (gross_income > 3000) {
return 0;
}
};
var deduction = calculateDeduction(selection, gross_income);
var income = gross_income - (social_security + health_insurance + unemployment + deduction);
var net_income = income - tax + deduction;
document.getElementById("deducerex").innerHTML = Math.round(deduction);