Wednesday, January 11, 2012

free math test generatorHow do I make a button that alternates between three links?

Hey,

I'm running an experiment online soon about urban navigation.

The experiment has three conditions which I won't tell you anything about in case you want you to participate hehe. I'm using http://www.weebly.com to design the website. Weebly has a drag and drop interface and one of the elements I can use is for custom HTML. I put the below random link code in one of these custom HTML elements thinking it would be good for assigning people to each of the three conditions (there is one webpage for each so I just replaced the javascriptsource links in the code example).


<!-- ONE STEP TO INSTALL RANDOM LINK GENERATOR:

1. Paste the designated coding into the HEAD of the HTML document -->

<!-- STEP ONE: Copy this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function go_to(url) {
window.location=url;
}
function rand_link() {
var a;
a = 1+Math.round(Math.random()*3); // a = random number between 1-3
if (a==1) go_to("http://bgeffects.javascriptsource…
if (a==2) go_to("http://clocks.javascriptsource.co…
if (a==3) go_to("http://games.javascriptsource.com…
}
// End -->
</SCRIPT>

<!-- STEP TWO: Paste this last code into the BODY of your HTML document -->

<BODY&gfree math test generatort;
<CENTER>
<FORM NAME="myForm">
<INPUT TYPE="button" NAME="myButton" VALUE="Random link"
onClick="rand_link()">
</FORM>
</CENTER>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.00 KB -->

When I tested the code, though, it sent people to the third link 50% of the time and the other two 25% of the time over a period of 100 trials. 100 is about the number of participants I expect for my experiment. I am wondering if there is a way to modify the code to ensure, over the course of 100 button clicks, a third go to each condition?

Alternatively, do you know an equally simple script I can just drop into one of these custom HTML elements which can alternate between the three conditions with each click of the button?

If you've got any solutions I'm all ears. If nothing can be done I'll just check which condition gets filled first then remove it from the list of links the code can randomly pick.

Also, feel free to check back at http://www.boommap.com (and tell others) in late April 2010 if you want to participate in my experiment! You can go in a draw to win a GPS at the end if you want.

Thanks!

Wil
I suggest replacing:

a = 1+Math.round(Math.randfree math test generatorom()*3); // a = random number between 1-3

with:

a = Math.ceil(Math.random()*3); // a = random number between 1-3


Rather than testing you page 100 times, I suggest using this short test script that will call this random number generator 100 times and count the results. Just reload the page several times to see the type of variation you may get. It will rarely be a third each.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html lang='en'>
<head>
<meta http-equiv='Content-type' content='text/html;charset=UTF-8'>
<title>Random Funciton</title>
</head>
<body>
<h1>Random Function</h1>
<script type="text/javascript">
function rand3() {
a = Math.ceil(Math.random()*3); // a = random number between 1-3
return a;
}
var result = new Array();
for (var i = 1; i <= 3; i++) {
result[i] = 0;
}
for (var i = 0; i < 100; i++)
{
result[rand3()] += 1;
}
for (var i = 1; i <= 3; i++) {
document.write("<p>result["+i+"] = "+result[i]+"<\/p>");
}
</script>
</body>
</html>

No comments:

Post a Comment