www.webdeveloper.com
Results 1 to 6 of 6

Thread: Random Pairing Generator

  1. #1
    Join Date
    May 2008
    Posts
    4

    Random Pairing Generator

    Okay, I am totally and completely new to javascript. I'm trying to create a random pairing generator. It's supposed to pick two names from the first array, and then pick a prompt to go with them from the second array. Unfortunately, when I tested it, no pairings or prompt came up, and when I clicked on the "try again" link, I got an error that the page doesn't exist. Some help would be greatly appreciated.
    PHP Code:
    <html>
    <
    head>
        <
    title>The Almost Totally Random Pairing Generator</title>
        <
    script language="JavaScript">
        <!--
            var 
    names = new Array(
                
    "Stella Bonasera"
                
    "Donald Flack, Jr."
                
    "Mac Taylor"
                
    "Sheldon Hawkes"
                
    "Lindsay Monroe"
                
    "Danny Messer"
                
    "Michelle Dessler"
                
    "Tony Almeida"
                
    "Jack Bauer"
                
    "Jack Shepherd"
                
    "James 'Sawyer' Ford"
                
                
            
    );
            
            var 
    phrases = new Array(
                
    "in the bathroom",
                
    "at a scene",
                
    "in the lab",
                
    "trust",
                
    "after midnight",
                
    "addiction",
                
    "a real date",
                
    "alone together",
                
    "awkward"
                
                
            
    );
            
            function = 
    generatePairing() {
                var 
    pairingPhrase "";
            
                
    // First person
                
    var index1 Math.floor(Math.random() * names.length);
                
    pairingPhrase += names[index1] + " / ";
                
                
    // Second person
                
    var index2 index1;
                while (
    index2 == index1) {
                    
    index2 Math.floor(Math.random() * names.length);
                }
                
    pairingPhrase += names[index2] + " / ";
                
                
    // Now the phrase
                
    var index3 Math.floor(Math.random() * phrases.length);
                
    pairingPhrase += phrases[index3];
                
                
    document.getElementById("pairingText").innerHTML pairingPhrase;
            }
        
    // -->
        
    </script>
    </head>


    <body bgcolor="black" link="#ccccc" alink="#669933" vlink="#669933">
    <center>
    <font face="verdana" size="5" color="#006699">The Almost Totally Random Pairing Generator</font>
    <br>
    <br>
    <br>

    <p>
    <center>

    <DIV ID="pairingText" STYLE="font-size: 16pt; font-weight: bold; font-family: Verdana; color: #000000;">
    </div>

    <SCRIPT LANGUAGE="JavaScript">
    <!--
        generatePairing();
    //-->
    </SCRIPT>

    <br>
    <br>



    <br>
    <font face="verdana" size="1" color="#006699">
    </center>
    <b>Want to try again? <a href="javascript:generatePairing();">Click here</a> for more!</b>
    <br>

    <br>Original design by
     <a href="mailto:quietgirl@trigun.com">Glowstick Chick</a> <br>(and occasionally messed up by Marie)</i>
    <br>
    <p>
    This version created by <a href="http://www.livejournal.com/users/failegaidin/" target="new">failegaidin</a> and as a lesson to all  this is what happens when boredom sets in.
    <p>
    You do all realize that if I personally get slash pairings, I'll be writing them as friendships, yes?.
    <p>
    This has been tested in Mozilla, IE 6 and Netscape 6 - it may not work in older browsers
    </font>

    </p>
    </body>

    </html> 

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Failegaidin
    Code:
            
            function = generatePairing() {
    The '=' does not belong there.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    May 2008
    Posts
    4
    I tried it without the '='. I meant to take that out before posting. I tried to get in contact with the author, but they aren't responding.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by Failegaidin
    I tried it without the '='. I meant to take that out before posting. I tried to get in contact with the author, but they aren't responding.
    It works without it. Maybe you can't see the text. Remove the black background to make it clearer.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  5. #5
    Join Date
    May 2008
    Posts
    4
    Ugh. It does work now. You're my hero. I was highlighting where the text was, thinking it would show up if it was just a color problem.

    The try again button still doesn't work though. Any suggestions?

  6. #6
    Join Date
    May 2008
    Posts
    4
    Nevermind - everything works now - thank you so much for your help!!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles