|
-
September 28th, 2009, 05:06 PM
#1
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>
-
September 28th, 2009, 05:40 PM
#2
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.
-
September 28th, 2009, 05:46 PM
#3
Re: Difficulty with simple Javascript code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|