Click to See Complete Forum and Search --> : Javascript story


dcslick
June 10th, 2005, 11:35 AM
I am in a web class and we have to create a story where the user inputs infomation and then javascript then puts that info into the story itself. Well I have the user input working correctly but I am having problems with putting the gathered info from the users into the story itself. Where the parenthesis are is where I want what used added to go into the story. Can someone please assist?

TIA


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<title>The Hare and the Tortoise</title>
</head>

<body>

<script type="text/javascript">
<!--
var story = "";

var a1, a2, a3, a4, a5, a6;
// prompts user for a name for the Hare
a1 = window.prompt("Enter a name for the Hare.", "");
// prompts the user for a name for the tortoise
a2 = window.prompt("Enter a name for the Tortoise.", "");
// prompts the user for a descriptive adjective
a3 = window.prompt("Enter a descriptive adjective.", "");
// prompts the user for a descriptive adjective
a4 = window.prompt("Enter another descriptive adjective.", "");
// prompts the user for a verb
a5 = window.prompt("Enter a verb.", "");
// prompts the user for a noun
a6 = window.prompt("And finally enter a noun.", "");

document.write(story);
//-->
</script>

<p>The Hare and the Tortoise<br>
<br>
The Hare was once boasting of his speed before the other
animals. &quot;I have never yet been beaten,&quot; said he, &quot;when I put forth my full
speed. I challenge any one here to race with me.&quot; <br>
<br>
The Tortoise (name goes here) said quietly, &quot;I accept your (descriptive adj)
challenge.&quot; <br>
<br>
&quot;That is a (descriptive adj) good joke,&quot; said the Hare; &quot;I could (enter a
verb)dance round you all the way.&quot; <br>
<br>
&quot;Keep your boasting till you've beaten,&quot; answered the Tortoise. &quot;Shall we race?&quot;
<br>
<br>
So a course was fixed and a start was made. The Hare darted almost out of sight
at once, but soon stopped and, believing that the Tortoise could never catch
him, lay down by the wayside to have a (noun)nap. The Tortoise never for a
moment stopped, but went on with a slow but steady pace straight to the end of
the course. <br>
<br>
When the Hare awoke from his nap, he saw the Tortoise just near the
winning-post. The Hare ran as fast as he could, but it was too late. He saw the
Tortoise had reached the goal. Then said the Tortoise: <br><br>
&quot;Slow and steady wins the race.&quot; </p>


</body>

</html>

Dr. Script
June 10th, 2005, 01:11 PM
If this is for a class, you must have a really bad teacher!. You're really not that close to getting this. I'd love to help, but this really doesn't seem like an attempt to solve the problem. The way to do it is easy, just change the story variable to have the entire story, and then write it. Apparently your teacher hasn't done a good job listening ... or you aren't living up to your job as a student.

dcslick
June 10th, 2005, 01:53 PM
Can you please point me in the direction on where to start looking into my code problems.

Thanks

Dr. Script
June 10th, 2005, 10:33 PM
Delete the <p>The Hare and the Tortoise<br>
<br>
The Hare was once boasting of his speed before the other
animals. &quot;I have never yet been beaten,&quot; said he, &quot;when I put forth my full
speed. I challenge any one here to race with me.&quot; <br>
<br>
The Tortoise (name goes here) said quietly, &quot;I accept your (descriptive adj)
challenge.&quot; <br>
<br>
&quot;That is a (descriptive adj) good joke,&quot; said the Hare; &quot;I could (enter a
verb)dance round you all the way.&quot; <br>
<br>
&quot;Keep your boasting till you've beaten,&quot; answered the Tortoise. &quot;Shall we race?&quot;
<br>
<br>
So a course was fixed and a start was made. The Hare darted almost out of sight
at once, but soon stopped and, believing that the Tortoise could never catch
him, lay down by the wayside to have a (noun)nap. The Tortoise never for a
moment stopped, but went on with a slow but steady pace straight to the end of
the course. <br>
<br>
When the Hare awoke from his nap, he saw the Tortoise just near the
winning-post. The Hare ran as fast as he could, but it was too late. He saw the
Tortoise had reached the goal. Then said the Tortoise: <br><br>
&quot;Slow and steady wins the race.&quot; </p> from the HTML, and add this before the document.write line:story = "<p>The Hare and the Tortoise<br>\n<br>\nThe Hare was once boasting of his speed
before the other animals. &quot;I have never yet been beaten,&quot; said he, &quot;when I put forth my full speed.
I challenge any one here to race with me.&quot; <br>\n<br>\nThe Tortoise "+ a2 +" said quietly, &quot;I accept
your "+ a3 +" challenge.&quot; <br>\n<br>\n&quot;That is a "+ a4 +" good joke,&quot; said the Hare; &quot;I could
"+ a5 +"dance round you all the way.&quot; <br>\n<br>\n&quot;Keep your boasting till you've beaten,
&quot; answered the Tortoise. &quot;Shall we race?&quot;<br>\n<br>\nSo a course was fixed and a start was
made. The Hare darted almost out of sight at once, but soon stopped and, believing that the Tortoise could
never catch him, lay down by the wayside to have a "+ a6 +"nap. The Tortoise never for a moment stopped,
but went on with a slow but steady pace straight to the end of the course. <br>\n<br>\nWhen the Hare awoke
from his nap, he saw the Tortoise just near the winning-post. The Hare ran as fast as he could, but it was too late.
He saw the Tortoise had reached the goal. Then said the Tortoise: <br><br>\n&quot;Slow and steady
wins the race.&quot; </p>" The other thing ... the Hare's name is never used anywhere ... Also, in the above code, remove any linebreaks (not the /n), the physical returns (end of each line displayed).

Dr. Script
June 10th, 2005, 10:35 PM
There is a better way that you probably don't know/understand yet. That would be leaving the story as is, and then changing the data in a span element to the inputted information.