Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2012, 09:35 AM   PM User | #1
Spency
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Spency is an unknown quantity at this point
Randomizing

Hello, I'm having issues trying to make an alphabetic randomizer... specifically, it needs to only randomize the order of 2 letters each time the page is reloaded.

Here is the code I currently have in place, but when I try and load it in my browser I get a blank screen.

Code:
<script type="text/javascript">
//<![CDATA[
<!--
Long.toHexString(Double.doubleToLongBits(Math.random()));

//

//-->
//]]>
</script>
This is the code I'm using for it, but it won't show up at all! I hijacked the code from here: http://mynotes.wordpress.com/2009/07...random-string/

Thank you in advance! Would it help if I posted my whole HTML file? It's not very big but it might help.
Spency is offline   Reply With Quote
Old 11-23-2012, 11:16 AM   PM User | #2
Spency
New to the CF scene

 
Join Date: Nov 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Spency is an unknown quantity at this point
Ok now I've decided to use a modified version of vwphillips's code from http://www.codingforums.com/archive/...p/t-89056.html

Code:
<html><head><title>Random Order</title>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/


var formAry=['Z','Y']
var scaleAry=['Y','Z']

var TO;

function Notes(id,spd){
var table=document.getElementById(id);
var cells=table.getElementsByTagName('TD');
table.style.fontSize='20px';
clearTimeout(TO);
NotesDo(cells,spd);
}

function NotesDo(cells,spd){
cells[2].innerHTML=formAry[Math.floor(Math.random()*formAry.length)];
cells[3].innerHTML=scaleAry[Math.floor(Math.random()*scaleAry.length)];
TO=setTimeout(function(){ NotesDo(cells,spd); },spd);
}

/*]]>*/
</script></head>

<body>
<table id="notes" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td width=100 align=center >First Test</td>
<td width=100 align=center >Second Test</td>
</tr>
<tr >
<td width=100 align=center >Z, Y</td>
<td width=100 align=center >Y, Z</td>
</tr>
</table>
<input type="button" value="Randomize" onclick="Notes('notes',10000);" />
</body>

</html>
Is there a way to make it so that the same characters do not show up in both cells? I tried removing one of the cells, but every time I did anything to modify the B cells I broke the randomizer completely.

Tips?
Spency is offline   Reply With Quote
Old 11-23-2012, 12:08 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
[QUOTE=Spency;1294201]Hello, I'm having issues trying to make an alphabetic randomizer... specifically, it needs to only randomize the order of 2 letters each time the page is reloaded.

Here is the code I currently have in place, but when I try and load it in my browser I get a blank screen.

Code:
<script type="text/javascript">
//<![CDATA[
<!--
Long.toHexString(Double.doubleToLongBits(Math.random()));

//

//-->
//]]>
</script>
That code is JAVA, not Javascript. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

If all you want to do is randomize the order of two letters on page load, then


Code:
<script type = "text/javascript">

var twoletters = "XY"
var now = new Date().getSeconds();  // returns 0-59
if (now%2 == 0) {  // even number
twoletters = "YX";
}
alert (twoletters);

</script>


Quizmaster: The small primates called lemurs are native to which large island off the coast of Africa?
Contestant: Argentina.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 11-23-2012 at 12:13 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 03:22 AM.


Advertisement
Log in to turn off these ads.