Results 1 to 7 of 7

Thread: Sentence generator help

  1. #1
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sentence generator help

    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.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by xx_mads_xx View Post
    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    lol, yeah. It's due and we didn't go over it in class but my teacher wants us to do it anyways.

  4. #4
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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 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

  5. #5
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    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!

Bookmarks

Posting Permissions

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