-
School Project....
Well, My Earth Science teacher asked us to program a random picture generator, one of one side of a coin, and another of the other side of the coin. I thought that it would be a good idea to program something using simple javascript. Problem is, I don't know how. I was wondering if someone could direct me to a tutorial site that might help me in my little project.
[edit]Ha! I beat you to it, TUN.[/edit]
-
isn't it kind of hard to make a random thing with two pics? you do it with js using the random number generator, and then that would pick which picture...but it'd be hard with two pictures, cause both would be repeated a lot..
-
Milkman - It's not so strange with only two possible random pictures. He's simply trying to simulate the flip of a coin with JavaScript, and wants to visually display that by usings heads & tails of a coin. It's a good exercise if you ask me.
Rich1988 - usually I don't like to go ahead and do all the work for you, but in this case, it's really simple, and therefore it's difficult for me to point you in the right direction without doing the entire thing anyways! So - here is a code-base you can work from, analyze it, learn it, play with it, do what you will with it. Hopefully it'll answer any questions you might have.
Code:
<html>
<head>
<title>Heads or Tails</title>
<script language="JavaScript">
function displayRandomCoin(){
now=new Date();
rand=now.getSeconds()%2+1;
if(rand==1) document.write("<img src=\"http://www.brokenwindow.net/coin_head.jpg\">");
else if(rand==2) document.write("<img src=\"http://www.brokenwindow.net/coin_tail.jpg\">");
}
</script>
</head>
<body>
<center>
<h3>Heads or Tails...</h3>
<script language="JavaScript">displayRandomCoin();</script>
</center>
</body>
</html>
-
Wow! I really wasn't expecting for you to do the work FOR me...but thanks anyway...I'll see if I can't learn what makes it tick and try and replicate it...Wish Me Luck!
http://www.geocities.com/digigodmon/HiroshimaBomb4.jpg
-
Thought I'd mention that there is also a Math.random() method.
-
Thanks Grizz, it's great to have a programmer of your calibre on the boards...The Math.Random() function was the thing i was talking about
-
Thanks Grizzly, I'll do it over the weekend and hand it in before Rich...:D