Javascript将无法运行

时间:2014-06-16 01:36:57

标签: javascript

我正在为一所学校的项目工作,我正在寻找为什么我的代码无法运行的原因。我确信这是一件我看不到的简单事。任何帮助都会很棒。

<!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 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) - parse Int (deductions));

        doument.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>

1 个答案:

答案 0 :(得分:0)

有一些拼写错误(函数名称中的空格,变量的错误大小写)和缺少函数getTaxRate()

在此处检查版本1和2之间的变形:http://plnkr.co/edit/0sLVnlTBwcHeYYOBvycO