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

  • SEARCH
  • Home
  • 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 8364577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:27:37+00:00 2026-06-09T12:27:37+00:00

I’ve been playing with random array arrangements and was wondering if there is a

  • 0

I’ve been playing with random array arrangements and was wondering if there is a way to pull word from the array only once. So every time you click on the changeWorld button then it will randomly draw from the array list until all the words where used only once?

Learning JavaScript so I don’t need anyone to write me the code, just want get pushed in the right direction and know if it is possable. There isn’t anything I can find that address the concept.

<body>

<button id="change-world-btn">Change World</button>

Hello <span class="world-name">World!</span><br />



<script type="text/javascript">

var worlds = new Array ("Pluto", "Mars", "Saturn", "Jupiter", "Uranus");

function newWorld() {
    return worlds[Math.floor(Math.random() * worlds.length)];
}

elements = document.getElementsByTagName('span');

document.getElementById('change-world-btn').onclick = function() {
    world = newWorld();
    for(var i = 0, el; el = elements[i++];) {
        if(el.className == 'world-name') {
            el.innerHTML = world;
        }
    }
};
</script>       
</body>
  • 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-06-09T12:27:39+00:00Added an answer on June 9, 2026 at 12:27 pm

    Remove the words that you have used from the array:

    function newWorld() {
      var index = Math.floor(Math.random() * worlds.length);
      var world = worlds[index];
      worlds.splice(index, 1);
      return world;
    }
    

    You might also want to check if the array is empty first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing with Java and mysql for awhile. But my first time using
Been playing around with JavaScript, and what Im trying to do is only allow
I've been playing around with Extractors lately and was wondering how the List extractors
Have been playing around with linq but there is one thing I cant seem
I have been playing with Boost.Random for a day now, and while boost::uniform_int_distribution<> works
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
Been playing around with this for a couple of hours and can't seem to
I been playing around with my code and I wanted to see what would
Ive been playing around with delegates trying to learn and I ran into one
I've been playing with the DataTable's RowChanged and RowChanging events, also with the TableNewRow

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.