JSFiddle - React, Tailwind, and code Playground
by raam86
HTML
<!-- Opening a HTML Form. -->
<form name="calculator">
<!-- Here user will enter 1st number. -->
שנת המס: <input type="text" name="taxYear" input disabled="disabled" value="2012">
<br>
<!-- Here user will enter the car price. -->
מחיר מחירון <input type="text" name="carPrice">
<img src="http://www.northamptonshire.gov.uk/_layouts/APPLICATIONS/Common/Icons/questionMark.gif">
<br>
<input type="checkbox" name="hybrid" >רכב היברידי
<img src="http://www.northamptonshire.gov.uk/_layouts/APPLICATIONS/Common/Icons/questionMark.gif">
<br>
<!-- Here user will input monthly salary -->
גובה משכורת <input type="text" name="wage">
<img src="http://www.northamptonshire.gov.uk/_layouts/APPLICATIONS/Common/Icons/questionMark.gif">
<br>
<input type="button" value="חשב" onclick="calc();">
<br>
<!-- Here car value will be displayed. -->
שווי שימוש <input type="text" name="total">
<br>
<!-- Here salary tax will be displayed. -->
תשלום חודשי למס הכנסה <input type="text" name="taxField">
<br>
</form>
JavaScript
function difference(diffWage) {
if (diffWage > 39430) {
return (diffWage - 39430);
}
if (diffWage > 18250) {
return diffWage - 18250;
}
if (diffWage > 12720) {
return diffWage - 12720;
}
if (diffWage > 8470) {
return diffWage - 8470;
}
if (diffWage >= 4770) {
return diffWage - 4770;
}
else {
return diffWage;
}
}
function taxStep(stepWage) {
if (stepWage >= 39340) {
return 0.43;
}
if (stepWage >= 18250) {
return 0.31;
}
if (stepWage >= 12720) {
return 0.28;
}
if (stepWage >= 8470) {
return 0.20;
}
if (stepWage >= 4771) {
return 0.14;
}
if (stepWage <= 4770) {
return 0.10;
}
}
function taxes(tax, taxWage) {
var minWage = 4770;
if (taxWage <= minWage) {
return tax;
}
else {
tax = tax + difference(taxWage) * taxStep(taxWage);
var newSalary = taxWage - difference(taxWage);
taxes(tax, newSalary);
}
}
function calc() {
var wage;
wage = document.calculator.wage.value;
var carTax;
var tax = 0;
var hybridDiscount = 520;
var useValue = 0.248;
var carPrice;
carPrice = document.calculator.carPrice.value;
carTax = useValue * carPrice;
if (document.calculator.hybrid.checked) {
carTax = carTax - hybridDiscount;
}
document.calculator.total.value = carTax;
document.calculator.taxField.value = taxes(tax, wage);
}