Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6387065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:06:20+00:00 2026-05-25T03:06:20+00:00

i am developing a jquery application. I have 10 divs with quotes. I am

  • 0

i am developing a jquery application. I have 10 divs with quotes. I am trying to create a function that takes a number and randomly displays that number of quotes from the 10 divs for 10 seconds and hide the divs. Then repeat the process again. I have not been able to do it please help me out. here is my code:

$(document).ready(function(){

    var div_number = 4;
    var used_numbers = new Array();
    var todo = setInterval(showQuotes(),3000);

    function showQuotes(){
        used_numbers.splice(0,used_numbers.length);
        $('.quotes').hide();
        for(var inc = 0; inc<div_number; inc++) {
            var random = get_random_number();
            $('.quotes:eq('+random+')').show();
        }
        $('.quotes').fadeOut(3000); 
    }

    function get_random_number(){
        var number = randomFromTo(0,9);
        if($.inArray(number, used_numbers) != -1) {
            get_random_number();
        }
        else {
            used_numbers.push(number);
            return number;
        }
    }
    function randomFromTo(from, to){
       return Math.floor(Math.random() * (to - from + 1) + from);
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:06:21+00:00Added an answer on May 25, 2026 at 3:06 am

    Changes I made:

    • hide the .quotes on launch via a stylesheet
    • run showQuotes() once before setInterval(showQuotes,10000), and
    • add a .delay() before fading the quotes out
    • Py’s ‘return’ added to get_random_number

    http://jsfiddle.net/cMQdj/1/

    the changed JavaScript:

    $(document).ready(function () {
        var div_number = 4;
        var used_numbers = new Array();
        showQuotes();
        var todo = setInterval(showQuotes, 10000);
    
        function showQuotes() {
            used_numbers.splice(0, used_numbers.length);
            $('.quotes').hide();
            for (var inc = 0; inc < div_number; inc++) {
                var random = get_random_number();
                $('.quotes:eq(' + random + ')').show();
            }
            $('.quotes').delay(6000).fadeOut(3000);
        }
    
        function get_random_number() {
            var number = randomFromTo(0, 9);
            if ($.inArray(number, used_numbers) != -1) {
                return get_random_number(); 
            } else {
                used_numbers.push(number);
                return number;
            }
        }
        function randomFromTo(from, to) {
            return Math.floor(Math.random() * (to - from + 1) + from);
        }
    });
    

    and add to your stylesheet:

    .quotes {display:none}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JQuery and Prototype in this web application that I'm developing. I'm looking
I'm developing an application with javascript. What I need is to have divs with
I am developing an application using jQuery that uses cookies. Right now, it is
I am developing an asp.net mvc web application that makes much use of jquery
I am developing a web application that displays images. I would like to display
we are developing a web application using MVC3 and Jquery. we have a situation
I am developing a mobile application using phonegap and jquery mobile. I have this
I am developing the application using jQuery Mobile 4.1. In my app, I have
I have this ajax web application I am developing that essentially calls the google
I'm developing a HTML5 application that uses jQuery. I want to make it multi

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.