Jump to content

Random Quote & Image! In 1!


houstonrockets16
 Share

Recommended Posts

Hi there,I need some help. I am trying to place random customer testimonials (using the random quote generator) on my right bar on the home page, and I would like that customers picture to show up underneath the random testimonial.Basically, if the random number is "1" then quote 1 and picture 1 need to show up.I got the quote part to work, but anytime I put any img tag in the code, nothing shows up or works. Could someone please help? My website is www.thegreatcanvas.com and my code so far is below! I knwo that I have the same random quote message right now... please help :) I couldn't find anything similar in the forums or on google!I will give whoever helps me a giftcard to my store :) <script>var num_of_quotes = 3;quotes = Math.floor (num_of_quotes * Math.random());if (quotes==0) {myRanQuote="My Dali painting turned out beautiful. It has really made my home look more hip! Thank you! <BR> Chris, TX";}if (quotes==1) {myRanQuote="My Dali painting turned out beautiful. It has really made my home look more hip! Thank you! <BR> Chris, TX";}if (quotes==2) {myRanQuote="My Dali painting turned out beautiful. It has really made my home look more hip! Thank you! <BR> Chris, TX";}document.write(myRanQuote);</script>

Link to comment
Share on other sites

Arrays would make it easier. All you have to do is use the generated random number on two different sets of data:

var quote = [];quote[0] = "Quote 1";quote[1] = "Quote 2";quote[2] = "Quote 3"; var image = [];image[0] = "file1.jpg";image[1] = "file2.jpg";image[2] = "file3.jpg"; var n = Math.floor(quote.length * Math.random()); document.write("<img src='" + image[n] + "' alt='[image]'>" + quote[n]);

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...