IT2805/Exercise 6/script.js

15 lines
515 B
JavaScript

const [incomeInput, wealthInput, taxInput] = ["incomeInput", 'wealthInput', 'taxInput']
.map(id => document.getElementById(id));
const tax = (income, wealth) => (0.35 * income) + (0.25 * wealth);
const updateTax = () => {
const [income, wealth] = [incomeInput.value, wealthInput.value]
.map(value => parseInt(value))
.map(value => isNaN(value) ? 0 : value);
taxInput.value = tax(income, wealth);
}
incomeInput.addEventListener('input', updateTax);
wealthInput.addEventListener('input', updateTax);