02-08-2011, 06:06 PM | #16 | |
Senior Member
Join Date: Dec 2010
Location: Australia
Posts: 146
|
Quote:
Great code! Simple and get things done.. 1 issue with the random algorithm though. Math.random() will generate value 1 > n > 0. So it will always be 0.12313 or whatever random decimal value it will find. Thus: var i = Math.floor(Math.random()*dare.length); will always give you 0s until you have 'dare' entries more that 10. The code should be: var i = Math.floor(Math.random()*1000*dare.length) % dare.length; That way, the random value will always be above 0, then get the remainder value when divided by number of 'dare' entries. |
|
02-08-2011, 06:10 PM | #17 |
Truth or Dare Enthusiast
Join Date: Oct 2009
Posts: 2,522
|
I think I understand what you're saying there, but his code works perfectly for me with only two entries?
|
02-08-2011, 06:15 PM | #18 |
getDare Sweetheart
Join Date: May 2010
Location: CA
Posts: 291
|
normally, yes that is a concern, but with arrays you start with entry 0 not 1
of course, this has nothing to do with what you said, so ignore me :P Last edited by OneMoreTime; 02-08-2011 at 06:24 PM. |
02-08-2011, 06:19 PM | #19 |
Senior Member
Join Date: Dec 2010
Location: Australia
Posts: 146
|
|
02-08-2011, 06:47 PM | #20 |
Truth or Dare Enthusiast
Join Date: Oct 2009
Posts: 2,522
|
Only semi related and entirely selfish question:
Is it possible to make it load a random image using javascript, too? |
02-08-2011, 07:20 PM | #21 |
getDare Sweetheart
Join Date: May 2010
Location: CA
Posts: 291
|
ya, it would be a similar idea, assuming you have a handle on the HTML part to add the button in, you need something like
HTML Code:
var image= new Array(); image.push("Image URL 1"); HTML Code:
function rotate_image() {
var i= Math.floor(Math.random()*image.length);
document.getElementById('dare_content').innerHTML = "<img src='"+image[i]+"'>";
Last edited by OneMoreTime; 02-08-2011 at 07:23 PM. |
02-08-2011, 07:22 PM | #22 |
Truth or Dare Enthusiast
Join Date: Oct 2009
Posts: 2,522
|
Thank you very much
Now to make it pretty, and my own little task generator will be complete |
02-10-2011, 08:20 AM | #23 |
Distinguished Member
|
As to image the image: if you have an image in the page, like
HTML Code:
<img src="images/image0.jpg" id="myimg"/>
HTML Code:
x=5; document.getElementById('myimg').src='images/image'+x+'.jpg';
__________________
Male, 18+ Likes: Underwear/swimwear, Anal toys, Some pain, Slight humiliation, Safe public, Naturism/nudism Curious about: CFNM, CMNM, BDSM, Public Limits: Public (reveal of identity), Too painful, Family/friends, Anything messy, Illegal, Dangereous Blog: my little encounters diary |
Advertisements |
|
|