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 8032729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:28:26+00:00 2026-06-05T01:28:26+00:00

function randomize() { var ra = Math.floor(Math.random()*ar.length=4); document.getElementById(‘es’).innerHTML = ar[ra]; } Is there a

  • 0
function randomize() {
var ra = Math.floor(Math.random()*ar.length=4);
document.getElementById('es').innerHTML = ar[ra];
}

Is there a way to short this code even more than it is? The reason why is because I’m going to be using this code a lot in other projects and objects and I cannot just call it inside like this: randomize(); because I have diffrent arrays.

  • 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-05T01:28:27+00:00Added an answer on June 5, 2026 at 1:28 am
    function randomize() {document.getElementById('es').innerHTML = ar[Math.floor(Math.random()*ar.length)];}
    

    But you wanted to use it more without a function call:

    function $(id) {
    return document.getElementById(id);
    }
    
    function randomize() {
    $('es').innerHTML = ar[Math.floor(Math.random()*ar.length)];
    }
    

    And instead of Math.floor, you can use ~~ for a microscopical faster diffrence.

    This saves some space and time if you are going to use it more. But if only one time, use the first example.

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

Sidebar

Related Questions

I have: function getRandomInt(min, max){ return Math.floor(Math.random() * (max - min + 1)) +
function randomString( len ) { // A random string of length 'len' made up
I have the following code function randomizer(start, end) { return Math.floor((end - start) *
I am wondering if the shuffle() array function is the correct way to randomize
I have a python function that randomize a dictionary representing a position specific scoring
function text_window() { var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open(GET,cd_catalog.xml,false); xmlDoc.send(); xmlDoc=xmlDoc.responseXML; }
Newbie question. Why is this JavaScript function returning undefined? var redis = require(redis), client
I'm looking for a function in ANSI C that would randomize an array just
I want a random expiration time on EACH iteration. This example will only randomize
what is the php function to randomize the associative array while keeping key/values pairs.

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.