Western Union - Cheap Broadband - Hookahs - Mobile Phones - Company Reports

PDA

View Full Version : While loop...


pixelpie
Dec 2nd 2007, 4:35 am
Hi, using Math.random(), I need to show one of six pictures every time I reload the page. I need to use the while loop too.

So far I have this, but it only shows four of the six pictures I have.

<script language="JavaScript">

var random = Math.random() ;
var picnum = Math.round(random*4)+1;

</script>
</head>

<script language="JavaScript">

document.write('<img src=picture/film'+picnum+'.jpg>')



</script>

Thanks for your help! :o

hrcerqueira
Dec 2nd 2007, 8:10 am
try this:

var picnum = parseInt(Math.random() * 6) + 1;

pixelpie
Dec 3rd 2007, 11:53 am
Doesn't seem to work but thanks for your help anyway!

hrcerqueira
Dec 3rd 2007, 12:11 pm
Of course it works... Unless you're using a very old browser it works flawlessly...

create a html page with just this in it:


<html>
<head></head>
<body>
<script>
var picnum = parseInt(Math.random() * 6) + 1;
alert(picnum);
</script>
</body>
</html>


then open it, and refresh it many times... you'll always get a number between 1 an 6.

If it still doesn't work for you, consider enabling javascript on your browser...