【问题标题】:Why am I receiving an error on </script> ? the error is (Uncaught SyntaxError: Unexpected end of input)为什么我在 </script> 上收到错误消息?错误是(未捕获的语法错误:输入意外结束)
【发布时间】:2020-02-26 01:47:05
【问题描述】:

基本上,我正在尝试创建一个运输履行程序,但我遇到了一个我无法自行调试的错误。谢谢大家。

<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
        <script type="text/javascript">
            var totalPrice = 0;
            var totalVolume = 0;
            var totalItem = 0;
            var numTrucks = 0;
            var productArray = ["LT","ST","DC","LC","PR","SP","SW"]; // 0 1 2 3 4 5 6
            var shippingvolumeArray = ["5.5","3","3.25","2","2.5","0.5","0.25"];
            var unitpriceArray = [1000,600,650,800,375,350,275];
            var productCode = Number(prompt("enter product code:"));
            var Quantity = prompt("enter quantity");

            do {
                var productCode = prompt("enter product code:");
                var Quantity = prompt("enter quantity:");
                for (var i = 0; i<= productArray.length; i++) {
                    if (productCode == productArray[i]) {
                        totalPrice = totalPrice + unitpriceArray[i] * Quantity;
                        totalVolume = totalVolume + shippingvolumeArray[i] + Quantity;
                        totalItem = totalItem + Quantity;
                    }
                }
                document.write(totalPrice);
            }
        </script>
    </body>
</html>

【问题讨论】:

    标签: javascript arrays error-handling while-loop do-loops


    【解决方案1】:

    您的do 循环未关闭,while 部分在那里丢失。应该是:

    do {
      var productCode = prompt("enter product code:");
      var Quantity = prompt("enter quantity:");
      for (var i = 0; i<= productArray.length; i++) {
        if (productCode == productArray[i]) {
          totalPrice = totalPrice + unitpriceArray[i] * Quantity;
          totalVolume = totalVolume + shippingvolumeArray[i] + Quantity;
          totalItem = totalItem + Quantity;
        }
      }
      document.write(totalPrice);
    } while (something);
    

    【讨论】:

    • 什么会取代(某物)?感谢您的快速回复。
    • 我可以通过用 (i !=== 0) 替换 Something 来解决吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2014-01-16
    • 2014-09-30
    • 1970-01-01
    相关资源
    最近更新 更多