PDA

View Full Version : Sentence generator help



xx_mads_xx
12-11-2006, 01:38 AM
I'm supposed to make a sentence using certain parts of the sentence that are randomly generated. Like there's five beginnings and five endings, etc. I just don't have the code for it in my text book. Can anyone give me the code for that? It'd be a huge help.

jscheuer1
12-11-2006, 04:36 AM
I'm supposed to make a sentence using certain parts of the sentence that are randomly generated. Like there's five beginnings and five endings, etc. I just don't have the code for it in my text book. Can anyone give me the code for that? It'd be a huge help.

You need help with your homework?

xx_mads_xx
12-11-2006, 04:55 AM
lol, yeah. It's due and we didn't go over it in class but my teacher wants us to do it anyways.

GhettoT
12-11-2006, 06:39 AM
Well, seeing as I don't like to DO homework for people who show no effort. I will only give you a few hints... If you base your script off of this (http://www.javascriptkit.com/script/script2/punchline.shtml) script , this should get you started. Next, as you can see there is only 1 array that is defined (quote) so you're gonna have to make a second one. Then that should get you aimed in the right direction... I think. Anyway, if you post what you get there is probably more people that can help make your work, work!

Good-luck!

-GT

xx_mads_xx
12-11-2006, 06:50 AM
Well, I found out how to do it for one, but I can't figure out how to let it do more than one. I have this so far.


var rancon = new Array();

rancon[0] = "Once upon a time,";
rancon[1] = "In a galaxy far, far away,";
rancon[2] = "On an unusually dark day,";
rancon[3] = "It was bright and sunny as usual ";
rancon[4] = "Good Gods, it was hot";

var rannum = Math.floor(Math.random()*rancon.length);

var rancon = new Array();

rancon[0] = "in the world of Ivalice";
rancon[1] = "in the desert city of Rabanastre";
rancon[2] = "outside the massive city Archades";
rancon[3] = "in the extremely creepy Bhujerba mines";
rancon[4] = "on the sunny Phon coast";

var rannum1 = Math.floor(Math.random()*rancon.length);


Now everytime I try it, it brings up two of the second Arrays. Still trying though.

jscheuer1
12-11-2006, 08:17 AM
Hints, I like that idea:

You've got to keep things separate even if it means doing the same thing several times but giving it different variable names each time. A more advanced way is to create a prototype object but, that's another lesson.

GhettoT
12-11-2006, 06:39 PM
Hints, I like that idea:

You've got to keep things separate even if it means doing the same thing several times but giving it different variable names each time. A more advanced way is to create a prototype object but, that's another lesson.

Yes, you need 2 different variable names (ie. 1st=ptone 2nd=pttwo)(part one and part two). As it is now you have the same name for both and then your math part is Math.floor(Math.random()*rancon.length) calling to the same thing which will definitely cause problems.

Just to sum all of that up into a short hint:
Change your variable names to so that they are not the same, then change your math so that it grabs one random part from the first variable(array) and another part from the second variable(array). Good luck again!