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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:08:58+00:00 2026-06-05T22:08:58+00:00

I’m trying to make a simple generator that takes some syllables from a user

  • 0

I’m trying to make a simple generator that takes some syllables from a user and randomly forms a made up word out of them.

I’ve managed to make a nice input system. It puts the syllables into a 2D array. I’ve tested it and it works.

When I try to alert random parts of the array it yells at me: “Uncaught TypeError: Cannot read property ‘0’ of undefined”

<html>
<head>
    <script type = "text/javascript">
        var sounds = [[],[],[]];

        function makeName(x){
            alert(x[0][random(x[0].length)] + x[1][random(x[1].length)] + x[2][random(x[2].length)]); //Something is wrong here
        }

        function random(x){ //Random number between 0 and x-1
            return Math.floor(Math.random()*x); //The problem might be here too
        }

        var Count0 = 0;
        var Count1 = 0;
        var Count2 = 0;

        function add(type, fooNum) {

            //Create an input type
            var element = document.createElement("input");

            //Add to index of user supplied data
            if(fooNum == 1){
                Count0++;
                element.setAttribute("id","0:" + Count0);
            }else if(fooNum == 2){
                Count1++;
                element.setAttribute("id","1:" + Count1);
            }else if(fooNum == 3){
                Count2++;
                element.setAttribute("id","2:" + Count2);
            }else{
                alert("Somethin' went wrong, man!");
            }

            console.log(element.id);

            //Assign different attributes to the element.
            element.setAttribute("type", type);
            element.setAttribute("value", "");
            var foo = document.getElementById("fooBar"+fooNum);

            //Append the element in page (in <span>).
            foo.appendChild(element);

        }

        function generate(){ //Assign the inputs to a 2D array
            var counts = [Count0, Count1, Count2];
            hello=counts;
            for(k=0; k<=2; k++){
                for(i=0; i<=counts[k]; i++){
                        sounds[k][i] = document.getElementById(k + ":" + i).value;
                        alert(sounds[k][i]);
                }
                i = 0;
            }
        }

    </script>
</head>
<body>
    <FORM>

        <INPUT type="button" value="Add" onclick="add(document.forms[0].element.value, 1)"/><INPUT type="text" name="element" id="0:0"/><span id="fooBar1">&nbsp;</span><P>
        <INPUT type="button" value="Add" onclick="add(document.forms[0].element.value, 2)"/><INPUT type="text" name="element" id="1:0"/><span id="fooBar2">&nbsp;</span><P>
        <INPUT type="button" value="Add" onclick="add(document.forms[0].element.value, 3)"/><INPUT type="text" name="element" id="2:0"/><span id="fooBar3">&nbsp;</span><P>

        <INPUT type="button" value="Generate" onclick="generate()"/><P>
        <INPUT type="button" value="Make Name" onclick="makeName()"/><P>
    </FORM>
</body>

My guess is that the problem lies within random() or makeName().

Please help! Thank you in advance.

  • 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-05T22:09:00+00:00Added an answer on June 5, 2026 at 10:09 pm

    Your makeName function takes argument x:

     function makeName(x) {
    

    but you call it like this:

    <INPUT type="button" value="Make Name" onclick="makeName()"/>
    

    that’s why x is undefined in makeName.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.