The basis of the assignment is to use the if/else if statements to set up the script. I need a little help finishing up the if/else part and for someone to look over any errors. Here's the assignment:
Write the JavaScript code in one HTML document using IF, and IF/Else statements for the following three situations. For each one make sure to write comments for each section.
Determine tax rate based on income and what the tax would be on the income.
Variable declarations section 1. Declare a variable that holds the income amount entered by the user. 2. Declare a variable that holds the minimum income that will not be charged taxes. 3. Declare a variable that holds the tax percentage for tax bracket 1. 4. Declare a variable that holds the tax percentage for tax bracket 2. 5. Declare a variable that holds the highest income for tax bracket 1. 6. Declare a variable that holds the highest income for tax bracket 2.
Assignments section 7. Assign $1500 as the highest income amount that will not be charged taxes. 8. Assign the highest income for tax bracket 1 to be $25K and the tax percent to 15%. Anything over $25K is in the next tax bracket. 9. Assign the highest income for tax bracket 2 to be $40K and the tax percent to 20%. Anything over $40K is in the next tax bracket. 10. Ask the user to enter a dollar amount. 11. Convert the data entered into a number.
Logic and Output section 12. Use only variables in your logic. 13. Determine whether or not the dollar amount entered is taxable. 14. Determine whether or not the dollar amount is in tax bracket 1 or 2. 15. Calculate the amount of tax on the dollar amount and display a message that tells the user what the tax amount would be on the number they entered. 16. For amounts greater than $40k display the message “I do not have the data to calculate the tax on this income.
Testing: Try values that are equal to the highest income for each bracket and the highest income for no taxes. Try numbers greater than the 40,000. Try amounts like 25,001 or 40,001.
My code thus far:
<script type="text/javascript">
// variable declarations
var userIncome;
var minIncomeNoTax;
var taxPercentBrack1;
var taxPercentBrack2;
var hiIncomeBrack1;
var hiIncomeBrack2;
var currentTaxBracket;
// Assignments
userIncome = prompt("Please enter your income in dollar amount.","");
minIncomeNoTax = 1500;
taxPercentBrack1 = 15/100;
taxPercentBrack2 = 20/100;
hiIncomeBrack1 = 25000;
hiIncomeBrack2 = 40000;
// Calculations & Output
if (userIncome >=minIncomeNoTax && userIncome <=hiIncomeBrack2)
{
alert("Your income is taxable.");
}
else if (userIncome >=minIncomeNoTax && userIncome <=hiIncomeBrack1)
{
alert("Your income amount is in tax bracket 1.");
}
else if (userIncome >hiIncomeBrack1 && userIncome <=hiIncomeBrack2)
{
alert("Your income amount is in tax bracket 2.");
}
else
{
alert("Sorry, I do not have the data to calculate the tax on this income.");
}
// output
document.write("Your Income: $" +userIncome + "<br />");
</script>