Portal Home > Knowledgebase > Articles Database > Simple Random Number Generator in Javascript


Simple Random Number Generator in Javascript




Posted by Freekers, 05-17-2010, 04:58 PM
Hi ! I am trying to create a simple random number generator in javascript, which generates numbers between 0 and 100 but also shows an image if the result is 0 or 100. This is what I have so far; Now I only need it to show an image if the random integer is 0 or 100. I have the images in .jpg format, so e.g 0.jpg and 100.jpg I know this should be extremely easy but I can't figure it out.. I also found this topic which shows random images but that's not what I want http://www.webmasterworld.com/forum48/1421.htm Thanks in advance !

Posted by n3r0x, 05-17-2010, 06:40 PM
could also be done by note: Math.floor(Math.random()*110); Should be Math.floor(Math.random()*101); Last edited by n3r0x; 05-17-2010 at 06:45 PM.

Posted by Freekers, 05-17-2010, 07:34 PM
Thanks soo much ! However, the images for number 0 and number 100 are different from each other, so I changed the code to this. Does this work too ? // Code to show image: Can this be pure HTML or should this be javascript too ?

Posted by n3r0x, 05-18-2010, 01:55 AM
It should be javascript..

Posted by Freekers, 05-18-2010, 05:59 AM
Thanks again for your reply. For some odd reason, my images aren't showing up. Here's the code I have now: I can see the random numbers, and 0 and 100 aren't displayed (That's correct). But the image doesn't appear if the number is 0 or 100...

Posted by n3r0x, 05-18-2010, 06:21 AM
thats because you don´t tell the javascript to display the images.. just to utilize a image space.. use something like there are other ways aswell.. like adding code into
s or s..

Posted by HostTantra, 05-19-2010, 11:34 PM
Its pretty simple. Just use the following code:

Posted by Freekers, 05-20-2010, 02:03 PM
Thanks for your help !



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Cobalt Expo (Views: 711)