In this exercise, you’ll use nested if statements and arithmetic expressions to calculate the income tax that is owed for a taxable income amount. When a user enters his taxable income and clicks the Calculate button, this application will display the federal income tax owed. This is the 2015 table for the federal income tax on individuals that you should use for calculating the tax: Taxable income Income tax Over… But not over… Of excess over… $0 $9,225 $0 plus 10% $0 $9,225 $37,450 $922.50 plus 15% $9,225 $37,450 $90,750 $5,156.25 plus 25% $37,450 $90,750 $189,300 $18,481.25 plus 28% $90,750 $189,300 $411,500 $46,075.25 plus 33% $189,300 $411,500 $413,200 $119,401.25 plus 35% $411,500 $413,200 $119,996,25 plus 39.6% $413,200 Open the HTML and JavaScript files in this folder: exercises_extrach04income_tax Note that the JavaScript file has some starting JavaScript code for this application, including the $ function and an onload event handler that attaches a function named processEntry to the click event of the Calculate button. Code the processEntry function. It should get the user’s entry and make sure it’s a valid number. If it isn’t, it should display an error message. If it is valid, it should pass the value to a function named calculateTax, which should return the tax amount. That amount should then be displayed in the second text box. Code the calculateTax function, but to start just write the code for calculating the the tax for any amount within the first two brackets in the table above. The tax should be rounded to two decimal places, and it should be returned to the calling function. To test this, use income values of 9225 and 37450, which should display taxable amounts of 922.50 and 5156.25. Add the JavaScript code for the next tax bracket. Then, if you have the time, add the JavaScript code for the remaining tax brackets.
In this exercise, you’ll use nested if statements and arithmetic
expressions to calculate the income tax that is owed for a taxable income amount. When a user enters his taxable income and clicks the Calculate button, this application will display the federal income tax owed.
This is the 2015 table for the federal income tax on individuals that you should use for calculating the tax:
| Taxable income | Income tax | ||
| Over… | But not over… | Of excess over… | |
| $0 | $9,225 | $0 plus 10% | $0 |
| $9,225 | $37,450 | $922.50 plus 15% | $9,225 |
| $37,450 | $90,750 | $5,156.25 plus 25% | $37,450 |
| $90,750 | $189,300 | $18,481.25 plus 28% | $90,750 |
| $189,300 | $411,500 | $46,075.25 plus 33% | $189,300 |
| $411,500 | $413,200 | $119,401.25 plus 35% | $411,500 |
| $413,200 | $119,996,25 plus 39.6% | $413,200 |
- Open the HTML and JavaScript files in this folder:
exercises_extrach04income_tax
Note that the JavaScript file has some starting JavaScript code for this application, including the $ function and an onload event handler that attaches a function named processEntry to the click event of the Calculate button.
- Code the processEntry function. It should get the user’s entry and make sure it’s a valid number. If it isn’t, it should display an error message. If it is valid, it should pass the value to a function named calculateTax, which should return the tax amount. That amount should then be displayed in the second text box.
- Code the calculateTax function, but to start just write the code for calculating the the tax for any amount within the first two brackets in the table above. The tax should be rounded to two decimal places, and it should be returned to the calling function. To test this, use income values of 9225 and 37450, which should display taxable amounts of 922.50 and 5156.25.
- Add the JavaScript code for the next tax bracket. Then, if you have the time, add the JavaScript code for the remaining tax brackets.