oosmoos
oosmoos

Reputation: 641

Simple JQuery Array

I'm trying to get a random generator of text and images which should be super simple but I cannot for the life of me figure out why it's not working out. Any help is greatly appreciated!

HTML Scroll Demo #1

<body>
    <div id="container">
        <p>Where would you live and what would you drive?</p>
        <p id="text"></p>
    </div>
</body>

CSS

#container {
width: 960px;
margin-left: auto;
margin-right: auto;
border: gray solid;
padding: auto;
background-image: url(../images/house.jpg) no-repeat;
}

#text {
font-size: 40px;
text-align: left;
}

p {
width: 100px;
color: black;
font-family: arial;
font-size: 18px;
text-align: left;
}

JQUERY

$(document).ready(function(){


  var car = ["limo", "golf cart", "pig"];
  var images = ["house.jpg", "dumpster.jpg", "mansion.jpg"];

  var x = images[Math.Floor(Math.random() * images.length)];

    document.getElementById("text").innerHTML=car[x];
  $('html').css({'background-image':'url(images/' + images [x] + ')'});
    });

Thanks in advance!

Upvotes: 2

Views: 57

Answers (1)

Blazemonger
Blazemonger

Reputation: 92953

You appear to expect x to be a number, not an image:

var x = Math.floor(Math.random() * images.length); // not Floor

Upvotes: 4

Related Questions