School Project....

Sharky Forums


Results 1 to 7 of 7

Thread: School Project....

  1. #1
    Reef Shark Rich1988's Avatar
    Join Date
    Mar 2002
    Posts
    387

    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]
    Last edited by Rich1988; 05-30-2002 at 04:43 PM.
    Proud Member of the SFOT Advocates

    "It's the little things you do while others aren't looking that end up shaping your future..."
    -me

    "Take the road less taken and......... run into less traffic..."
    -lol

  2. #2
    Tiger Shark
    Join Date
    Mar 2001
    Location
    Next door.
    Posts
    546
    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..
    BLAH

  3. #3
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    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>

  4. #4
    Reef Shark Rich1988's Avatar
    Join Date
    Mar 2002
    Posts
    387
    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!

    Last edited by Rich1988; 06-01-2002 at 10:11 PM.
    Proud Member of the SFOT Advocates

    "It's the little things you do while others aren't looking that end up shaping your future..."
    -me

    "Take the road less taken and......... run into less traffic..."
    -lol

  5. #5
    Tiger Shark
    Join Date
    Mar 2001
    Posts
    615
    Thought I'd mention that there is also a Math.random() method.
    System specs:


    | Core i5 750 | GA-P55A-UD3 | 4.0 GB G.skill DDR3 1600 | eVGA 470 GTX |
    | Intel X25-M 80 GB SSD | WD 5000AAKS | Lian Li PC-7FN | Corsair TX750W |
    | Windows 7 Home 64-bit |

  6. #6
    Tiger Shark
    Join Date
    Mar 2001
    Location
    Next door.
    Posts
    546
    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
    BLAH

  7. #7
    Don't run with scissors!! TheUltimateNewbie's Avatar
    Join Date
    May 2001
    Location
    Long Island, New York
    Posts
    5,258
    Thanks Grizzly, I'll do it over the weekend and hand it in before Rich...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •