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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:12:51+00:00 2026-05-25T02:12:51+00:00

Sometimes the randomly-generated letter equals to ‘undefined’ Anyone know why? Code: <script type=text/javascript> var

  • 0

Sometimes the randomly-generated letter equals to ‘undefined’

Anyone know why?

Code:

<script type="text/javascript"> 
var myArray= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];

randomnumber=Math.floor(Math.random()*27);
alert(myArray[randomnumber]);
  • 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-25T02:12:52+00:00Added an answer on May 25, 2026 at 2:12 am

    Well, it could have something to do with your Math.floor(Math.random()*27) using the number 27 when there are 26 letters in the English alphabet.

    math random returns 0-.999... 
    math random * 27 returns 0-26.999...
    floor math random * 27 returns 0 - 26 
    an array with every english letter has 26 items 
    which means it has items indexed from 0-25
    

    so you get a blank in each box 1/27 of all loads. However, once “#next” has been seeded it will always stay a “letter” because you’re replacing it with

    $("#next").text(good[randomnumber]);
    

    When randomnumber=27 good[randomnumber]=undefined and $("#next").text(undefined) does nothing so the contents of “#next” remain unchanged. Still broken, less obvious. Just change 27 to 26 and you’re done.

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

Sidebar

Related Questions

I have a very weird problem with core text, which sometimes randomly and sometimes
I have this program, but cin in randomly skips.. I mean sometimes it does,
Sometimes IE6 will render the text of a <ul> list the same color as
Sometimes I have to work on code that moves the computer clock forward. In
Sometimes a labeled break or continue can make code a lot more readable. OUTERLOOP:
I noticed that sometimes(randomly) my Mootools ajax request gets send twice. The second request
I'm trying to edit an aspx page...mainly javascript, and I randomly see changes that
I know that most javascript email obfuscation solutions stop bots dead in their tracks
I'm baffled. My site randomly throws the following error: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException'
Occasionally during debugging the debugger skips forward randomly. Sometimes I Step into a function

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.