SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Heg's Avatar
    Join Date
    Dec 2001
    Location
    AZ
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is wrong w/ my code

    In the following script, why does 299.jpg never load?
    The script works, but after refreshing about 50 times, it only randomly shows 220.jpg and 304.jpg.


    <script>
    var whichpic=Math.round(Math.random())*3
    if (whichpic<=1)
    document.write('<img src="images/220.jpg">')
    else if (whichpic<=2)
    document.write('<img src="images/299.jpg">')
    else if (whichpic<=3)
    document.write('<img src="images/304.jpg">')
    </script>

    Thanks,

    Rob

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var whichpic=Math.round(Math.random()*3 )

    Put the * 3 within the bracket.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Enthusiast Heg's Avatar
    Join Date
    Dec 2001
    Location
    AZ
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome. Thank you Maelstrom.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •