View Full Version : Java Script Problems
Savizzaviz
03-08-2002, 11:23 PM
I have attached a java script thing that is supose to generate a whole story completely randomly. The thing is is that it doesn't do anything. I have know idea what is wrong and I am hoping someone here does. I know its a long script but most of it is just the different words that could be chosen and, by what I could tell, there was not too much actual script other then that.
Thanks :P
Savizzaviz
03-09-2002, 11:14 PM
Anyone?
I thought there was supose to be losts of people who knows this stuff. Where are you? Though is only been up for like 2 day I just don't want this to end up unanswer because no one found it.
and again,
Thanks :D
Dr. Web
03-10-2002, 12:46 AM
can you post the link to the site where you originally got the code? Thanks.
Savizzaviz
03-10-2002, 12:58 PM
Sure can:
JavaScript Source (http://javascript.internet.com/messages/sentence.html)
Jon Hanlon
03-12-2002, 01:54 AM
Unlike Java, Javascript does not require a semi-colon (;) at the end of each statement. This can however, sometimes place restrictions on the free-format ability of the language.
Change:
function GenPreposition() {
var n = 14
var r = qrand(n)
var w = ""
if ( r == 0 ) w = "of"else if ( r == 1 ) w = "from"
else if ( r == 2 ) w = "near"else if ( r == 3 ) w = "about"
else if ( r == 4 ) w = "around"else if ( r == 5 ) w = "for"
else if ( r == 6 ) w = "toward"
else if ( r == 7 ) w = "over"
else if ( r == 8 ) w = "behind"
else if ( r == 9 ) w = "beyond"
else if ( r == 10 ) w = "related to"
else if ( r == 11 ) w = "defined by"
else if ( r == 12 ) w = "inside"
else if ( r == 13 ) w = "living with"
return w
}
To Be:
function GenPreposition() {
var n = 14
var r = qrand(n)
var w = "";
if (r == 0) w = "of"
else if (r == 1) w = "from"
else if ( r == 2 ) w = "near"
else if ( r == 3 ) w = "about"
else if ( r == 4 ) w = "around"
else if ( r == 5 ) w = "for"
else if ( r == 6 ) w = "toward"
else if ( r == 7 ) w = "over"
else if ( r == 8 ) w = "behind"
else if ( r == 9 ) w = "beyond"
else if ( r == 10 ) w = "related to"
else if ( r == 11 ) w = "defined by"
else if ( r == 12 ) w = "inside"
else if ( r == 13 ) w = "living with"
return w
}
Savizzaviz
03-12-2002, 03:43 PM
Thanks Jon,
That must have been a lot of work for you to figure out and I very much appreciate it.
Thanks again :D
Savizzaviz
03-12-2002, 03:48 PM
By the way...
Is there any possible, easy, way I could make this script only generate one sentance?
Jon Hanlon
03-12-2002, 04:40 PM
Remove the last script block entirely. That is, delete:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
qinit()
document.write ( "<h2>Introduction</h2>" )
for ( i=0; i<5; i++ ) {
document.write ( GenRandomSentence(), " " )
}
for ( j=0; j<3; j++ ) {
document.write ( "<h2>", CapFirst(GenNounPhrase(0)), "</h2>" )
for ( i=0; i<5; i++ ) {
document.write ( GenRandomSentence(), " " )
}
}
document.write ( "<h2>Conclusions</h2>" )
for ( i=0; i<5; i++ ) {
document.write ( GenRandomSentence(), " " )
}
// End -->
</SCRIPT>
And replace it with:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
qinit()
document.write(GenRandomSentence(), " ")
// End -->
</SCRIPT>
Savizzaviz
03-12-2002, 05:38 PM
Well thanks again Jon,
You've been a big help. :D
If only you could fix the rest of my site. ;)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.