Changed around line 1
+ // Tax rates and calculations
+ const federalTaxBrackets = [
+ { min: 0, max: 9950, rate: 0.10 },
+ { min: 9951, max: 40525, rate: 0.12 },
+ { min: 40526, max: 86375, rate: 0.22 },
+ { min: 86376, max: 164925, rate: 0.24 },
+ { min: 164926, max: 209425, rate: 0.32 },
+ { min: 209426, max: 523600, rate: 0.35 },
+ { min: 523601, max: Infinity, rate: 0.37 }
+ ];
+
+ const FICA_TAX_RATE = 0.0765;
+
+ function calculateFederalTax(income) {
+ let tax = 0;
+ for (const bracket of federalTaxBrackets) {
+ if (income > bracket.min) {
+ const taxableAmount = Math.min(income, bracket.max) - bracket.min;
+ tax += taxableAmount * bracket.rate;
+ }
+ }
+ return tax;
+ }
+
+ function calculateNetSalary(grossSalary) {
+ const federalTax = calculateFederalTax(grossSalary);
+ const ficaTax = grossSalary * FICA_TAX_RATE;
+ const netSalary = grossSalary - federalTax - ficaTax;
+ return netSalary;
+ }
+
+ // Chart setup
+ const ctx = document.getElementById('salaryChart').getContext('2d');
+ const salaryChart = new Chart(ctx, {
+ type: 'doughnut',
+ data: {
+ labels: ['Net Salary', 'Taxes'],
+ datasets: [{
+ data: [0, 0],
+ backgroundColor: ['#4a90e2', '#ff6384'],
+ borderWidth: 0
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ plugins: {
+ legend: {
+ position: 'bottom'
+ }
+ }
+ }
+ });
+
+ // Event listeners
+ document.getElementById('calculateBtn').addEventListener('click', () => {
+ const grossSalary = parseFloat(document.getElementById('grossSalary').value);
+
+ if (isNaN(grossSalary) || grossSalary <= 0) {
+ alert('Please enter a valid gross salary');
+ return;
+ }
+
+ const netSalary = calculateNetSalary(grossSalary);
+ const ratio = (netSalary / grossSalary).toFixed(2);
+
+ // Update chart
+ salaryChart.data.datasets[0].data = [netSalary, grossSalary - netSalary];
+ salaryChart.update();
+
+ // Update ratio display
+ document.querySelector('.ratio-value').textContent = ratio;
+ });
+
+ // Initialize state dropdown
+ const states = [
+ 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware',
+ 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky',
+ 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',
+ 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico',
+ 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania',
+ 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
+ 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
+ ];
+
+ const stateSelect = document.getElementById('state');
+ states.forEach(state => {
+ const option = document.createElement('option');
+ option.value = state.toLowerCase();
+ option.textContent = state;
+ stateSelect.appendChild(option);
+ });