user3508959
user3508959

Reputation: 1

JavaScript within HTML not executing

I've recently begun learning HTML and JavaScript and am in the process of creating a simple video rental script in Notepad++. After creating the script, it fails to execute locally in any browser. I am curious as to what parts may have been improperly used or if I am missing something entirely, thank you.

<!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>

Upvotes: 0

Views: 61

Answers (1)

NS0
NS0

Reputation: 6096

You have a few missing +'s. You forgot one when adding name and "<br />" on line 20 and then, when formatting with new lines, you need to use pluses as well.

Also, double is not a thing that exists in Javascript. You can define variables using only var (for local scope) or with no prefix.

Try the following

<!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>

Upvotes: 4

Related Questions