Javascript函数没有运行

时间:2014-06-16 03:29:36

标签: javascript

我正在为一所学校的项目工作,我很难让一切运行起来。目前,将显示提示“输入您的年终收入”和“输入您当年的应纳税扣除额”,输出结果为:

Welcome to COP 2500 Tax Service!

Your taxable income is $5300

我希望得到:

Welcome to COP 2500 Tax Service!

Your taxable income is $5300

Based on a taxable income of $5300 your tax rate is 10 percent

Your calculated taxes owed are $530

You overpaid your taxes, you will receive a refund of $120

Thank you for using COP 2500 Tax Service!

任何帮助都会很棒。感谢

<!DOCTYPE HTML>
<html>
<head>
   <script type="text/javascript">
   const TEN = 0.10;
   const FIFTEEN = 0.15;
   const TWENTYFIVE = 0.25;
   const TWENTYEIGHT = 0.28;
   const THRITYTHREE = 0.33;
   const THIRTYFIVE = 0.35;
   const THREENINETYSIX = 0.396;


function getTaxRate(inIncome); {
   var income = parseInt(inIncome);
   var taxRate;

   if (income <= 8925 && income >= 0) {
    taxRate = TEN;
   }
   else if (income >= 8926 && income <= 36250) {
    taxRate = FIFTEEN;
   }
   else if (income >= 36251 && income <= 87850) {
    taxRate = TWENTYFIVE;
   }
   else if (income >= 87851 && income <= 183250) {
    taxRate = TWENTYEIGHT;
   }
   else if (income >= 183251 && income <= 398350) {
    taxRate = THRITYTHREE;
   }
   else if (income >= 398351 && income <= 400000) {
    taxRate = THIRTYFIVE;
   }
   else if {
    taxRate = THREENINETYSIX;
   }
   return taxRate;
   }   



   function calculateTaxes(inTaxableIncome, inTaxRate) {
  var income = parseInt(inTaxableIncome);
  var rate = parseFloat(inTaxRate);
  var taxesOwed = income * rate;
  return taxesOwed;
  }

function refundOrPay(inTaxesOwed, inTaxesPaid) {
  var taxesOwed = parseInt(inTaxesOwed);
  var taxesPaid = parseInt(inTaxesPaid);
  var taxDifference = taxesOwed - taxesPaid;
  return taxDifference;
}

  </script>
</head>
<body>
    <script type="text/javascript">
        document.writeln("Welcome to COP 2500 Tax Service!<br>");

        //Determine the tax rate
        var income = prompt("Enter your year-end income");
        var deductions = prompt("Enter your taxable deductions for the year", "");

        var taxableIncome = (parseInt(income) - parseInt(deductions));

        document.writeln("Your taxable income is $" + taxableIncome + "<br>");
        var rate = getTaxRate(taxableIncome);

        document.writeln("Based on a taxable income of $" + taxableIncome + " your tax rate is " + rate * 100 + " percent<br>")

         var taxesOwed = calculateTaxes(taxableIncome, rate);

        document.writeln("Your calculated taxes owed are $" + taxesOwed + "<br>");

        var taxesPaid = prompt("Enter the taxes you paid for the year", "");
        var taxResult = refundOrPay(taxesOwed, taxesPaid);

        if (taxResult == 0) {
          document.writeln("Congratulations you broke even!<br>");
        } else if (taxResult > 0) {
          document.writeln("Unfortunately you still owe more, please pay an additional $" + taxResult + " by April 15, 2014<br>");
        } else {
          document.writeln("You overpaid your taxes, you will recieve a refund of $" + (-1 * taxResult) + "<br>");
}

        document.writeln("Thank you for using COP 2500 Tax Service!");
    </script>
    </body>
</html>

0 个答案:

没有答案