HTML中的JavaScript未执行

时间:2017-04-24 21:36:54

标签: javascript html html5

我最近开始学习HTML和JavaScript,并且正在使用Notepad ++创建一个简单的视频租借脚本。创建脚本后,它无法在任何浏览器中本地执行。我很好奇哪些部分可能被错误使用,或者我完全遗漏了什么,谢谢。



<!DOCTYPE html>
<html>

<head>

</head>

<body>

  <script type="text/javascript">
    var name = window.prompt("Hello, what is your name?");
    var choice = window.prompt("DVD or Blu-Ray?");
    var days = parseInt(window.prompt("How many days are you renting for?"));


    if (choice == "DVD") {
      double dvdcst = 2.99;
      double dvdtot = dvdcst * days;
      document.write("Name: " + name "<br />"
        "Days renting: " + days + "<br />"
        "Cost per day: " + dvdcst + "<br />"
        "Total cost: " + dvdtot + "<br />");
    } else if (choice == "Blu-Ray") {
      double blucst = 3.99;
      double blutot = blucst * days;
      document.write("Name: " + name + "<br />"
        "Days renting: " + days + "<br />"
        "Cost per day: " + blucst + "<br />"
        "Total cost: " + blutot + "<br />");
    }
  </script>


</body>

</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:4)

您遗失了一些+。在第20行添加name"<br />"时忘记了一个,然后,在使用新行格式化时,您还需要使用加号。

此外,double不是Javascript中存在的东西。您只能使用var(对于本地范围)或没有前缀来定义变量。

尝试以下

<!DOCTYPE html>
<html>

   <head>

    </head>

    <body>

            <script type="text/javascript">
            var name = window.prompt("Hello, what is your name?");
            var choice = window.prompt("DVD or Blu-Ray?");
            var days = parseInt(window.prompt("How many days are you renting for?"));


            if (choice == "DVD")
            {
                dvdcst = 2.99;
                dvdtot = dvdcst * days;
                document.write("Name: " + name + "<br />"+
                "Days renting: " + days + "<br />"+
                "Cost per day: " + dvdcst + "<br />"+
                "Total cost: " + dvdtot + "<br />");
            }

            else if (choice == "Blu-Ray")
            {
                blucst = 3.99;
                blutot =  blucst * days;
                document.write("Name: " + name + "<br />"+
                "Days renting: " + days + "<br />"+
                "Cost per day: " + blucst + "<br />"+
                "Total cost: " + blutot + "<br />");
            }


        </script>


   </body>

</html>