Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [DHTML]Random Comedy Quote Picker

  1. #1
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Lightbulb [DHTML]Random Comedy Quote Picker

    1) CODE TITLE:
    Random Comedy Quote Picker
    2) AUTHOR NAME/NOTES:
    Matthewbluewars
    3) DESCRIPTION:
    Chooses a random comedy quote from a list.
    4) URL TO CODE:
    http://dhtml.wikia.com/wiki/Random_C...uote_Generator
    or, ATTACHED BELOW (see #3 in guidelines below):

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For this to be really useful, you should promote it not just for comedy quotes. It's just a random something displayer from a list. So, likely it would be quotes or facts, but it might be, for example, a fortune cookie generator.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    matthewbluewars (04-11-2008)

  4. #3
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default

    Good idea.

  5. #4
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Post [DHTML] Random Comedy Quote Generator II

    1) CODE TITLE:
    Random Comedy Quote Generator II
    2) AUTHOR NAME/NOTES:
    Matthewbluewars
    3) DESCRIPTION:
    Unlike Matthewbluewars's previous generator which picks from a list, this one fills in the blanks of "If ____ _____, then there would be _____ _____," randomly. Sample output:
    4) URL TO CODE:
    Instructions: http://lightbulbproductions.net/blog...dom-quote-gen/
    Preview: http://lightbulbproductions.net/webt...domquoteII.htm
    or, ATTACHED BELOW (see #3 in guidelines below):
    Last edited by matthewbluewars; 04-10-2008 at 10:17 PM.

  6. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I like the first one a little bit better than that second one. Also, I think it could be better if the quotes were in a config array variable (if that makes sense) that way all of the quotes are not on one line (or even make a seperate js file just for the quotes themselves).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The second one also appears not very random at all-- the results are almost identical. Every quote was Santa Claus or Britney Spears, US president or ruled the world, more, and explosions. Nothing else appears, even after refreshing at least 15 times.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I think the reason for that being there aren't enough "quotes" or "items" in the array to make it random the way we expect it to.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. The Following User Says Thank You to thetestingsite For This Useful Post:

    matthewbluewars (04-11-2008)

  10. #8
    Join Date
    Dec 2007
    Location
    Ankara, Turkey
    Posts
    160
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    You can connect to random.org via HTTPRequest object to get real numbers or sequences everytime

  11. #9
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Your code is erroneous. Array.length refers to the number of arguments the Array constructor function is defined with. What you want is a.length, b.length, etc.

    You should also use Math.floor, not Math.round. Flooring gives [0, length), whereas rounding gives [0, length].

    Code:
    if(!Array.prototype.map)
      Array.prototype.map = function(f /*, context */) {
        for(var r = [], i = 0, n = this.length, t = arguments[1]; i < n; ++i)
          r[i] = f.call(t, this[i], i, this);
        return r;
      };
    
    function generate() {
      document.getElementById("message").innerHTML = [
        "If",
        ["Santa Claus", "Britney Spears", "Fish E. Guy", "Batman", "Al Gore", "Mickey Mouse", "Eli Manning"],
        ["ruled the world", "was US president"],
        "there would be",
        ["more", "less"],
        ["explosions.", "donuts.", "dolphin rebellions.", "99% taxes", "EVIL!!!"]
      ].map(function(a) {
        return typeof a != "string"
          ? a[Math.floor(Math.random() * a.length)]
          : a;
      }).join(' ');
    }
    Trinithis

  12. #10
    Join Date
    Apr 2008
    Posts
    38
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default

    I fixed it! Now the code reads:
    Code:
    <html>
    
    <head>
    
    <script language="javascript" type="text/javascript">
    /*
     * Random Comedy Quote Generator
     * by Matthewbluewars
     * The Web Experience Blog
     * http : // blog.lightbulbproductions.net /
     */
    function generate()
    {
       var a = ["Santa Claus", "Britney Spears", "Fish E. Guy", "Batman", "Al Gore", "Mickey Mouse", "Eli Manning"];
       var b = [" ruled the world", " was US president"];
       var c = [" more", " less", " no more", " a lot more", " too many", " not enough"];
       var d = [" explosions.", " donuts.", " dolphin rebellions.", " of these comedy quote generators.", " EVIL!!!"];
       var message = "If " + a[Math.floor(Math.random() * a.length)] + "" + b[Math.floor(Math.random() * b.length)] + " there would be" + c[Math.floor(Math.random() * b.length)] + d[Math.floor(Math.random() * d.length)];
       document.getElementById("message").innerHTML = message;
    }
    </script>
    
    <title></title>
    
    </head>
    
    <body>
    <div id="message"></div>
    <button id="generate" onclick="generate()">Generate New</button><br />
    <p style="color:red;">WARNING: THIS IS COMPLETELY RANDOM SO WE DON'T EVEN KNOW WHAT IT'S GOING TO SHOW.</p>
    </body>
    
    </html>

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
  •