Replacing Numbers Array With Images

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5

60 Replies - 2017 Views - Last Post: 25 October 2013 - 08:32 PM

#61 EdNolan  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 334
  • Joined: 22-September 13

Re: Replacing Numbers Array With Images

Posted 25 October 2013 - 08:32 PM

I think I finally got it. I had to move the clone array out of the for loop. I realized it kept cloning. I will do more tests with this Saturday to make sure. But I think it's working correctly. Once I confirm no duplicates I will split it into the first 9 pics and then 28 more pics like I need it. But so far no dupes!
<script type="text/javascript">

var imgArray = ["1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png", "9.png", "10.png", 
"11.png", "12.png", "13.png", "14.png", "15.png", "16.png", "17.png", "18.png", "19.png", 
"20.png", "21.png", "22.png", "23.png", "24.png", "25.png", "26.png", "27.png", "28.png", "29.png", 
"30.png", "31.png", "32.png", "33.png", "34.png", "35.png", "36.png", "37.png", "38.png", "39.png"];
           //make a clone of imgArray

var basePath = "///C:/Users/Dads/Desktop/game/";

function imgRandom() {
var clone = imgArray.slice(0);
for (i = 0; i < 37; i++) {
        var i, rand, image;
        var shownImages = [];
var randIndex = Math.floor(Math.random() * clone.length);
var rand = clone[randIndex];
        image = new Image();    // or new Image(72, 96);
        image.src = basePath + rand;
        shownImages.push(rand);
//        console.log(shownImages[0])
        image.width = 36;
        image.height = 48;
        document.body.appendChild(image);
clone.splice(randIndex,1);
}
}
imgRandom()
        </script>


Thank you everyone, especially Dormilich for putting up with me, and sticking with me.

This post has been edited by Dormilich: 25 October 2013 - 09:40 PM

Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5