CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Difficulty with simple Javascript code

    Hello,
    When this code is loaded on a webpage, no prompt pops up. Why is this simple code not working?



    <html>
    <head>
    <title>Story</title>
    </head>
    <body>
    <h1 style="text-align:center"><span style="color:black"> Story for CPSC 125 </span></h1>

    <script type="text/javascript">
    Name = prompt("Enter your first name:");
    University = prompt("Enter a name of a University:");
    Study = prompt("Enter an area of study (Computer Science, French, etc...):");
    Dangerous = prompt("Enter a dangerous activity:")
    lunch = prompt("Enter a lunch item:");


    document.write("<p>... " + Name + " was a student at " + University + " who studied " + Study + "</p>");
    document.write("<p> + Name + " was not very good at writing stories, but " + Name + " had a unique taste for " + Dangerous + ");
    document.write("After a long day of " + Dangerous + " "," " + Name + " made a " + lunch + "</p>);


    </script>

    </body>
    </html>

  2. #2
    Join Date
    Oct 2005
    Posts
    158

    Re: Difficulty with simple Javascript code

    Try this out. You had quotes in the wrong place. I moved the <script> before the body also, cause that's how I roll.
    ps. You should also declare your variables before you use them.

    Code:
    <html>
    <head>
    <title>Story</title>
    </head>
    <script type="text/javascript">
    Name = prompt("Enter your first name:");
    University = prompt("Enter a name of a University:");
    Study = prompt("Enter an area of study (Computer Science, French, etc...):");
    Dangerous = prompt("Enter a dangerous activity:")
    lunch = prompt("Enter a lunch item:");
    
    
    document.write("<p>... " + Name + " was a student at " + University + " who studied " + Study + "</p>");
    document.write("<p> " + Name + " was not very good at writing stories, but " + Name + " had a unique taste for " + Dangerous);
    document.write("After a long day of " + Dangerous + " "," " + Name + " made a " + lunch + "</p>)");
    
    
    </script>
    <body>
    <h1 style="text-align:center"><span style="color:black"> Story for CPSC 125 </span></h1>
    
    
    
    </body>
    </html>
    Last edited by stin; September 28th, 2009 at 05:43 PM.

  3. #3
    Join Date
    Sep 2009
    Posts
    2

    Re: Difficulty with simple Javascript code

    Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured