--- /dev/null
+function load_tax_table(table_id, deductible_id) {
+ return apply_deductible(parse_tax_table(document.getElementById(table_id).value),
+ parseFloat(document.getElementById(deductible_id).value));
+}
+
+function format_number(n) {
+ return n.toLocaleString('en', {useGrouping:true, style: 'currency', currency: 'USD'});
+}
+
+function calculate() {
+ const table1 = load_tax_table('tax_table_1', 'deductible_1');
+ const table2 = load_tax_table('tax_table_2', 'deductible_2');
+ 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);
+
+ 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));
+}