PDA

View Full Version : [DHTML]Random Comedy Quote Picker



matthewbluewars
04-05-2008, 10:37 PM
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_Comedy_Quote_Generator
or, ATTACHED BELOW (see #3 in guidelines below):

djr33
04-05-2008, 11:32 PM
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.

matthewbluewars
04-10-2008, 09:32 PM
Good idea.

matthewbluewars
04-10-2008, 09:48 PM
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/2008/04/09/random-quote-gen/
Preview: http://lightbulbproductions.net/webtools/uploads/randomquoteII.htm
or, ATTACHED BELOW (see #3 in guidelines below):

thetestingsite
04-10-2008, 10:29 PM
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).

djr33
04-11-2008, 12:06 AM
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.

thetestingsite
04-11-2008, 12:10 AM
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.

BYK
04-11-2008, 05:13 AM
You can connect to random.org via HTTPRequest object to get real numbers or sequences everytime ;)

Trinithis
04-11-2008, 05:30 AM
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].



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(' ');
}

matthewbluewars
04-11-2008, 05:20 PM
I fixed it! Now the code reads:

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

rangana
04-12-2008, 01:55 AM
Have you consider someone who wants your script, but does'nt understand the code ;)

...For instance, like the code here in DD, it has a Step by Step instructions with the most flexible way to edit the codes :)

...With yours, the user would have to edit each arrays..just to have the jokes...and also, if we could minimize script, much better ;)

This is a complete rendition, but maybe useful:


function generate()
{
/********************************************* edit here *********************************************/

var joke1 = 'If Eli Manning was US president there would be more explosions.';
var joke2 = 'If Fish E. Guy ruled the world there would be less EVIL!!!';
var joke3 = 'If Mickey Mouse was US president there would be less of these comedy quote generators.';
var joke4 = 'If Britney Spears was US president there would be less donuts.';
var joke5 = 'If Santa Claus was US president there would be less EVIL!!!';
var joke6 = 'If Mickey Mouse ruled the world there would be more EVIL!!!';
var joke7 = 'If Eli Manning ruled the world there would be more donuts.'

/*********************************************************************************************************************/
var jokes=[joke1, joke2, joke3, joke4, joke5, joke6, joke7];
var random=Math.floor(Math.random()*jokes.length);
document.getElementById('message').firstChild.nodeValue=jokes[random];
}


...PS.place at least &nbsp; in your message div ;)

matthewbluewars
06-01-2008, 04:15 PM
You can connect to random.org via HTTPRequest object to get real numbers or sequences everytime ;)
I acually got the idea to do that and am working on it.