www.webdeveloper.com
Results 1 to 4 of 4

Thread: Random Word Generator Coding Problems

  1. #1
    Join Date
    Jul 2014
    Posts
    3

    Angry Random Word Generator Coding Problems

    I used this and even tried again using the updated versions described in this post but I just cannot get it. I got it to work, multiple times, but instead of single words, I want it to give multiple word responses. Like, "a red rose" as a result or longer results (quotes) such as "Be yourself; everyone else is already taken".

    In addition, I'd like a word generator that will give me 3 results each time, but again, each result needs to be more than one word (like, "a red rose"). I can code for one word, but for some reason when I code for more than one, it all goes to hell.

    Looking to integrate into my tumblr theme, if that matters at all.

  2. #2
    Join Date
    Nov 2010
    Posts
    1,097
    I was going to say google it, but all the examples I found were hideously outdated. Basically:
    - make an array of quotes
    - shuffle the array
    - specify how many quotes you want to display (3 in this case)
    - show the first 3 quotes of the shuffled array

    Code:
    <body>
    <div id="disp"></div>
    
    <script>
    (function (){
    var numofquotes = 3, str="", quotes = [
        "Stay Hungry. Stay Foolish - Steve Jobs",
        "Good Artists Copy, Great Artists Steal - Pablo Picasso",
        "Argue with idiots, and you become an idiot - Paul Graham",
        "Be yourself; everyone else is already taken - Oscar Wilde",
        "Simplicity is the ultimate sophistication - Leonardo Da Vinci"
      ];
    
    function shuffle(array) {
    var n = array.length, k, t;
    if (n == 0) {return false};
    while (--n) {
    k = Math.floor(Math.random() * (n+1));
    t = array[n];
    array[n] = array[k];
    array[k] = t;
    }
    }
    
    shuffle(quotes);
    
    
    for (i=0; i< numofquotes; i++){
    str+=quotes[i]+"<br>";
    }
    document.getElementById("disp").innerHTML=str;
    })();
    </script>
    
    </body>

  3. #3
    Join Date
    Jul 2014
    Posts
    3
    Doesn't work! This is the page (if that matters) and I put the code I used below*. Maybe it matters that it's on tumblr? I don't think it should, because single word generators of the same sort work just fine. I also used this code without the:
    <SCRIPT LANGUAGE="JavaScript">
    <div id="disp"></div>
    <FORM NAME="WordForm">
    <INPUT TYPE=TEXT SIZE=100 NAME="WordBox"><BR>
    <INPUT TYPE=BUTTON onClick="PickRandomWord(document.WordForm)"
    VALUE="Click Here to Get a Random Starter">
    </FORM>

    AND
    I input it raw, as in, without anything you didn't give me. No matter what I do, it just doesn't work.


    *the code I used:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head>
    <title>3 Elements</title>
    <link rel="shortcut icon" href="{Favicon}">

    <style type="text/css">
    html {
    background: url(http://nanobitwallpaper.com/wp-conte...-wallpaper.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    }

    p{margin-top:-64px;padding-left:90px;}
    body{font-family:arial;color:#fff; text-shadow: 1px 1px #000;}
    b, strong {color:#fff; text-shadow: 1px 1px #000;}
    a{text-decoration:none;-webkit-transition: all 0.3s ease-in-out;-moz-transition: all 0.3s ease-in-out;-o-transition: all 0.3s ease-in-out;-ms-transition: all 0.3s ease-in-out;transition: all 0.3s ease-in-out;}
    a:hover{-webkit-transition: all 0.3s ease-in-out;-moz-transition: all 0.3s ease-in-out;-o-transition: all 0.3s ease-in-out;-ms-transition: all 0.3s ease-in-out;transition: all 0.3s ease-in-out;}
    #wrap{margin-top:100px;margin:0 auto;width:500px;;height:auto;}
    #space{margin-top:80px;}
    .title{font-size:40px;letter-spacing:-3px;text-align:center;color:#fff;font-weight:bold; text-shadow: 1px 1px #000;}
    #links{font-size:25px;font-weight:bold;margin-top:20px;color:#b2e1ec; text-align:center}
    #links a{font-size:30px;text-decoration:none;letter-spacing:-2px;-webkit-transition: all 0.5s;-moz-transition: all 0.5s;transition: all 0.5s;color:#b2e1ec;}
    #links a:hover{color:#7ca9b4;}
    .q{font-size:20px;font-weight:bold;color:#b2e1ec;text-transform:lowercase;font-style:italic;}
    .a{font-size:13px;}
    .c a{font-family:arial;font-size:12px;color:#000;bottom:3px;right:8px;position:fixed;letter-spacing:-1px;font-weight:bold;text-align:center;}
    .c a:hover{color:#f65878;}
    ::-moz-selection {background-color: #E8BF56;color: #fff;}
    ::selection{background-color: #E8BF56;color: #fff;}

    </style>




    <center><div id="wrap">
    <div id="space"></div>
    <div class="title">story starter generator</div><br>

    <div class="q">What is a starter?</div>
    <div class="a"> a starter is simply the first line of a story. You can use it as the first line, and work off from there, or you can just use it as inspiration and stick it in the middle or end of the fic. It's more challenging and fun if you use it as the first line of a drabble or oneshot, though! All starters do involve klaroline, but they are <i>not</i> the same as <a href="http://tvdfanficassist.tumblr.com/scenarios">scenarios</a> or <a href="http://tvdfanficassist.tumblr.com/3elements">elements</a> </div><br>


    <body>


    <SCRIPT LANGUAGE="JavaScript">
    <div id="disp"></div>
    <FORM NAME="WordForm">
    <INPUT TYPE=TEXT SIZE=100 NAME="WordBox"><BR>
    <INPUT TYPE=BUTTON onClick="PickRandomWord(document.WordForm)"
    VALUE="Click Here to Get a Random Starter">
    </FORM>
    <script>
    (function (){
    var numofquotes = 3, str="", quotes = [
    "Stay Hungry. Stay Foolish - Steve Jobs",
    "Good Artists Copy, Great Artists Steal - Pablo Picasso",
    "Argue with idiots, and you become an idiot - Paul Graham",
    "Be yourself; everyone else is already taken - Oscar Wilde",
    "Simplicity is the ultimate sophistication - Leonardo Da Vinci"
    ];

    function shuffle(array) {
    var n = array.length, k, t;
    if (n == 0) {return false};
    while (--n) {
    k = Math.floor(Math.random() * (n+1));
    t = array[n];
    array[n] = array[k];
    array[k] = t;
    }
    }

    shuffle(quotes);


    for (i=5; i< numofquotes; i++){
    str+=quotes[i]+"<br>";
    }
    document.getElementById("disp").innerHTML=str;
    })();
    </script>

    </body>
    </SCRIPT>

    <div id="links"><a href="/">← back</a></div> </center>
    </div>




    </html>

  4. #4
    Join Date
    Nov 2010
    Posts
    1,097
    Quote Originally Posted by andelielovely View Post
    I input it raw, as in, without anything you didn't give me. No matter what I do, it just doesn't work.
    Really?

    My version:
    Code:
    for (i=0; i< numofquotes; i++){
    Your version:
    Code:
    for (i=5; i< numofquotes; i++){
    My version:
    Code:
    <body>
    <div id="disp"></div>
    
    <script>
    Your version:
    Code:
    <body>
    
    
    <SCRIPT LANGUAGE="JavaScript">
    <div id="disp"></div>
    your markup is a hideous, nostalgic mess that scores a whopping 35 errors on the W3 validator (http://validator.w3.org/check). I recommend starting over, somewhere post-2005

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