<style>
td { padding: .5em; vertical-align: top}
textarea { height: 12em; }
+ textarea.small { height: 4em; }
input { width: 7em }
.output { padding: 1em; background-color: #eee; border: thin solid #888; width: max-content; }
.privacy_policy { margin-top: 5em; }
</td>
</tr>
<tr>
+<td>
+Social Security tax<br/>
+<textarea id="tax_table_3" class="small" onchange="calculate()" oninput="calculate()"> 0 6.2
+ 160200 0</textarea>
+</td>
+<td>
+Medicare tax<br/>
+<textarea id="tax_table_4" class="small" onchange="calculate()" oninput="calculate()"> 0 1.45
+ 250000 2.35</textarea>
+</td>
+</tr>
+<tr>
<td colspan="2">
Desired after-tax salary</br>
<input id="after_tax" value="100000" onchange="calculate()" oninput="calculate()">
<strong><span id="before_tax"></span> before tax</strong>
- <span id="tax_1"></span> federal tax
- <span id="tax_2"></span> state tax
+ - <span id="tax_3"></span> social security tax
+ - <span id="tax_4"></span> medicare tax
= <span id="after_tax_verification"></span> after tax.
</p>
}
function calculate() {
- const table1 = load_tax_table('tax_table_1', 'deductible_1');
- const table2 = load_tax_table('tax_table_2', 'deductible_2');
+ const tax_tables = [
+ load_tax_table('tax_table_1', 'deductible_1'),
+ load_tax_table('tax_table_2', 'deductible_2'),
+ load_tax_table('tax_table_3'),
+ load_tax_table('tax_table_4')
+ ];
const after_tax = parseFloat(document.getElementById('after_tax').value);
- const before_tax = invert(merge_tax_tables(table1, table2))(after_tax);
-
- const tax1 = tax(table1, before_tax);
- const tax2 = tax(table2, before_tax);
+ const merged_tax_table = tax_tables.reduce(merge_tax_tables);
+ const before_tax = invert(merged_tax_table)(after_tax);
+ const taxes = tax_tables.map(t => tax(t, before_tax));
document.getElementById('before_tax').textContent = format_number(before_tax);
- document.getElementById('tax_1').textContent = format_number(tax1);
- document.getElementById('tax_2').textContent = format_number(tax2);
- document.getElementById('after_tax_verification').textContent = format_number(before_tax - (tax1 + tax2));
+ document.getElementById('tax_1').textContent = format_number(taxes[0]);
+ document.getElementById('tax_2').textContent = format_number(taxes[1]);
+ document.getElementById('tax_3').textContent = format_number(taxes[2]);
+ document.getElementById('tax_4').textContent = format_number(taxes[3]);
+ document.getElementById('after_tax_verification').textContent = format_number(before_tax - sum(taxes));
}