# Random images in javascript

**URL:** https://forum.kirupa.com/t/random-images-in-javascript/328239
**Category:** Uncategorized
**Created:** [April 30, 2012, 2:30pm UTC](https://forum.kirupa.com/t/random-images-in-javascript/328239 "2012-04-30T14:30:47Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ksuguy25](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@Ksuguy25](https://forum.kirupa.com/u/Ksuguy25)
#### Post date: [April 30, 2012, 2:30pm UTC](https://forum.kirupa.com/t/random-images-in-javascript/328239/1 "2012-04-30T14:30:47Z")

</div>

Hello,

I’m creating a program in javascript that randoms number generator to select numbers from 1-6 and displays the results of 30 rolls of a die using images. i have a table of 8 cells wide. Still its giving me problems but here is the code

```php
window.onload = randomDice;

function randomDice() {
    var myPix = new Array("images/dice1.jpg","images/dice2.jpg","images/dice3.jpg" ,"images/dice4.jpg" ,"images/dice5.jpg" ,"images/dice6.jpg");
    var randomNum = Math.floor(( 1 + Math.random() * 6));
    document.getElementById("myPicture").src = document.getElementById("onscreen").src;
    document.getElementById("myPicture2").src = myPix[randomNum];
    document.getElementById("myPicture3").src = myPix[randomNum];
}

</script>

<table width="500" border="0">
  <tr>
    <td></td>
    <td><img src="images/spacer.gif" id="myPicture" alt="some image"></td>
    <td><img src="images/spacer.gif" id="myPicture2" alt="some image"></td>
    <td><img src="images/spacer.gif" id="myPicture3" alt="some image"></td>
    <td><img src="images/spacer.gif" id="myPicture4" alt="some image"></td>

```
