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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:45:38+00:00 2026-06-15T01:45:38+00:00

This is a very simple question/problem, and I can easily work around it, but

  • 0

This is a very simple question/problem, and I can easily work around it, but since I’m learning javascript I was very eager to know WHY exactly this particular problem is happening.

$("#go").click(function() {
    $("p").append(array[x] + " ")
    functionlist[array[x]]()
    x++
})​

This does not work as I expect it to. I want it to write the current content of array, perform a simple animation that is associated with a certain function name, and then increment x. Everything works, except it doesn’t increment x.

If I do this:

$("#go").click(function() {
    $("p").append(array[x] + " ")
    //functionlist[array[x]]()
    x++
})​

x is incremented successfully.

So my question is, why does this happen?

Here is a link to a jsfiddle that I am using: http://jsfiddle.net/mxy6N/3/

  • 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-15T01:45:40+00:00Added an answer on June 15, 2026 at 1:45 am

    Well, if you check your script console (F12 is most browsers), you’ll see that functionlist[array[x]]() throws an error something like:

    Object has no method “smooch”

    This is because array[x] is equal to “smooch”, and functionlist["smooch"] is undefined, so it errors out before it makes it to your x++.

    Other things going on in this code:

    • x is declared inside of your function, therefore it will always be 0 at the time it is used.
    • even if it were declared outside of your function, as you increment it, it will run out of items to look at in your array. You’ll need to use a modulo operator or two here.
    • You’re not referencing an .js files that have a definition for $.fn.transition, so your transition calls will also error out.
    • flip and flop both have the same rotateY value, so once it “flips” it won’t “flop”

    Here is something that might do what you’re looking to do: http://jsfiddle.net/g5mJd/3/

    And the updated code:

    var array = ["smooch", "jab", "flip"];
    var move = "flip";
    var x = 0;
    var functionlist = {
        flip: function() {
            $("#block").transition({
                perspective: '0px',
                rotateY: '180deg'
            }, 1000);
        },
        flop: function() {
            $("#block").transition({
                perspective: '0px',
                rotateY: '0deg'
            }, 100);
        }
    };
    
    
    $("#go").click(function() {
        var functionName = (x % 2 == 0) ? 'flip' : 'flop';
        var fn = functionlist[functionName];
        if($.isFunction(fn)) {
            fn();
        }
        var say = array[x % array.length];
        $('p').append(say + ' ');
        x++;
    })​;
    

    EDIT: Updated with $.isFunction() check.

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

Sidebar

Related Questions

This is a very simple question, but I can't seem to find something about
This may be very simple question,But please help me. i wanted to know what
I'm sure this is a very simple question, but embarrassed to say I can't
This is probably a very simple question so please forgive my ignorance, but can
I know this is a very simple question but I have been struggling with
Its very simple question, I'm new to this and I can't understand the problem
This is a very simple question for compiler guys, but I always get confused
This is a very simple question and I feel stupid for asking it, but
This isn't a very simple question, but hopefully someone has run across it. I
Okay my question is probably very simple for some of you but I can

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.