digic25
05-07-2006, 05:49 PM
How would I go about switching this script to a switch statement, with the generated random value (1-10) displaying the correct website.
Any help is appreciated.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function isRandom() {
for(i=0;i<=10;i++) {
var value = Math.random()*10; //generates a random number between 1 and
10.
value = Math.floor(value); //converts value to a whole number.
if (value%2 == 0){
Random = value;
}
}
document.write(n_2 + " " +"http://www.msn.com"+"<br>");
document.write(n_4 + " " +"http://www.yahoo.com"+"<br>");
document.write(n_6 + " " +"http://www.monster.com"+"<br>");
document.write(n_8 + " " +"http://www.hotjobs.com"+"<br>");
document.write(n_1 + " " +"http://www.google.com"+"<br>");
document.write(n_3 + " " +"http://www.google.com"+"<br>");
document.write(n_5 + " " +"http://www.google.com"+"<br>");
document.write(n_7 + " " +"http://www.google.com"+"<br>");
document.write(n_9 + " " +"http://www.google.com"+"<br>");
document.write(n_10 + " " +"http://www.google.com"+"<br>");
}
</script>
</head>
<body>
<script type="text/javascript">
isRandom();
</script>
</body>
</html>
Any help is appreciated.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function isRandom() {
for(i=0;i<=10;i++) {
var value = Math.random()*10; //generates a random number between 1 and
10.
value = Math.floor(value); //converts value to a whole number.
if (value%2 == 0){
Random = value;
}
}
document.write(n_2 + " " +"http://www.msn.com"+"<br>");
document.write(n_4 + " " +"http://www.yahoo.com"+"<br>");
document.write(n_6 + " " +"http://www.monster.com"+"<br>");
document.write(n_8 + " " +"http://www.hotjobs.com"+"<br>");
document.write(n_1 + " " +"http://www.google.com"+"<br>");
document.write(n_3 + " " +"http://www.google.com"+"<br>");
document.write(n_5 + " " +"http://www.google.com"+"<br>");
document.write(n_7 + " " +"http://www.google.com"+"<br>");
document.write(n_9 + " " +"http://www.google.com"+"<br>");
document.write(n_10 + " " +"http://www.google.com"+"<br>");
}
</script>
</head>
<body>
<script type="text/javascript">
isRandom();
</script>
</body>
</html>