javascript question

Out of context: Reply #1

  • Started
  • Last post
  • 4 Responses
  • xrusos0

    here's the image rotate script contained within script tags in the head... (that i want to move to a .js file)

    // JavaScript to interpolate random images into a page.
    var ic = 11; // Number of alternative images
    var xoxo = new Array(ic); // Array to hold filenames

    xoxo[0] = "/images/highlanders.jpg";
    xoxo[1] = "/images/car.jpg";
    xoxo[2] = "/images/broken_dock.jpg";
    xoxo[3] = "/images/lighthouse.jpg";
    xoxo[4] = "/images/bird.jpg";
    xoxo[5] = "/images/red_barn.jpg";
    xoxo[6] = "/images/deck.jpg";
    xoxo[7] = "/images/fog.jpg";
    xoxo[8] = "/images/subway.jpg";
    xoxo[9] = "/images/highlanders.jpg";
    xoxo[10] = "/images/highlanders.jpg";

    function pickRandom(range) {
    if (Math.random)
    return Math.round(Math.random() * (range-1));
    else {
    var now = new Date();
    return (now.getTime() / 1000) % range;
    }
    }
    // Write out an IMG tag, using a randomly-chosen image name.
    var choice = pickRandom(ic);
    // -->

View thread