Go Back   getDare Truth or Dare > Tangents > Lounge > Advice Section

Reply
 
Thread Tools Display Modes
Old 02-08-2011, 06:06 PM   #16
nerdboy
Senior Member
 
nerdboy's Avatar
 
Join Date: Dec 2010
Location: Australia
Posts: 146
Default

Quote:
Originally Posted by OneMoreTime View Post
HTML Code:
<script type="text/javascript">
/**
Simply add the following to the code to make either new truths or dares 
dare.push("blah"); 
truth.push("blah"); 
**/
var dare = new Array();
        dare.push("dare 1");
        dare.push("dare 2");

var truth = new Array();
        truth.push('truth 1');
        truth.push('truth 2');

                
function rotate_dare()  {
        var i = Math.floor(Math.random()*dare.length);
    document.getElementById('dare_content').innerHTML = dare[i];
        document.getElementById('dice_roll').innerHTML = '';
}
function rotate_truth() {
        var i= Math.floor(Math.random()*truth.length);
        document.getElementById('dare_content').innerHTML = truth[i];
                document.getElementById('dice_roll').innerHTML = '';

}

</script>
<table cellpadding="5" cellspacing="3" align="center" style="background-color:#EDE685">
<tr>
<td colspan="2" align="center" width="500" style="font-family:Times New Roman;"><b>Truth or Dare?</b></td>
</tr>
<tr>
<td align="center"><input type="button" value="Truth" border="0" onclick="javascript:rotate_truth()" /></td>
<td align="center"><input type="button" value="Dare" border="0" onclick="javascript:rotate_dare()" /></td>
</tr>
<tr>
<td id="dare_content" colspan="2" width="500" align="center">Go ahead, ask for a truth ... I dare you!</td>
</tr>
</table>
again, you would have to add new entries manually, but once they are added you can easily open up the HTML page in any browser and grab random dares/truths/whatever you want

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.

nerdboy is offline   Reply With Quote
Old 02-08-2011, 06:10 PM   #17
Leopard
Truth or Dare Enthusiast
 
Join Date: Oct 2009
Posts: 2,522
Default

I think I understand what you're saying there, but his code works perfectly for me with only two entries?
Leopard is offline   Reply With Quote
Old 02-08-2011, 06:15 PM   #18
OneMoreTime
getDare Sweetheart
 
OneMoreTime's Avatar
 
Join Date: May 2010
Location: CA
Posts: 291
Default

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.
OneMoreTime is offline   Reply With Quote
Old 02-08-2011, 06:19 PM   #19
nerdboy
Senior Member
 
nerdboy's Avatar
 
Join Date: Dec 2010
Location: Australia
Posts: 146
Default

Quote:
Originally Posted by Leopard View Post
I think I understand what you're saying there, but his code works perfectly for me with only two entries?
Actually his method works too. My bad.
floor(0.8 * 2) = 1
floor(0.4 * 2) = 0
nerdboy is offline   Reply With Quote
Old 02-08-2011, 06:47 PM   #20
Leopard
Truth or Dare Enthusiast
 
Join Date: Oct 2009
Posts: 2,522
Default

Only semi related and entirely selfish question:

Is it possible to make it load a random image using javascript, too?
Leopard is offline   Reply With Quote
Old 02-08-2011, 07:20 PM   #21
OneMoreTime
getDare Sweetheart
 
OneMoreTime's Avatar
 
Join Date: May 2010
Location: CA
Posts: 291
Default

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]+"'>";
Of course the site color parsed it weird so its hard to see, but there is a nested quote in the innerHTML here, so a url with any sort of quotes will not work.

Last edited by OneMoreTime; 02-08-2011 at 07:23 PM.
OneMoreTime is offline   Reply With Quote
Old 02-08-2011, 07:22 PM   #22
Leopard
Truth or Dare Enthusiast
 
Join Date: Oct 2009
Posts: 2,522
Default

Thank you very much

Now to make it pretty, and my own little task generator will be complete
Leopard is offline   Reply With Quote
Old 02-10-2011, 08:20 AM   #23
321tt
Distinguished Member
 
321tt's Avatar
 
Join Date: Jan 2011
Posts: 778
Blog Entries: 28
Default

As to image the image: if you have an image in the page, like
HTML Code:
<img src="images/image0.jpg" id="myimg"/>
then in JavaScript you can put

HTML Code:
x=5;
document.getElementById('myimg').src='images/image'+x+'.jpg';
and it'll do your job. Just don't forget the id property with the image.
__________________
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
321tt is offline   Reply With Quote
Reply

Advertisements
Kink Talk


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:42 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc. - Also check out Kink Talk!reptilelaborer