0

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>

3
  • 4
    Open your browser's developer tools and read the error message. Commented Apr 24, 2017 at 21:38
  • 1
    Not sure what the canonical dupe is, but the problem is you have to use the + at the end of each line to continue the string. So "Days renting: " + days + "<br />" becomes "Days renting: " + days + "<br />" + Commented Apr 24, 2017 at 21:41
  • Unrelated, but may be helpful. dvdcst * days and blucst * days may give non money formatted results such as 6.1 instead of 6.10. Commented Apr 24, 2017 at 21:44

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Also note that you removed the "double" type's from the variables.
Yes, true, will explain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.