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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:10:24+00:00 2026-05-31T03:10:24+00:00

I’m having some logic trouble with a bit of jQuery I’m writing. I suspect

  • 0

I’m having some logic trouble with a bit of jQuery I’m writing. I suspect I’m doing something wrong with my global variables, but I’m not exactly sure what the problem is. I’m logging everything as it’s running, and for some reason, in my rollDown() function, although I’m using id++, my global id variable is not being updated (as shown in logs).

I need to update my global variable so that when I click header > a, the else if statement will run instead of once again firing rollDown().

Here’s the relevant code:

var id = 0;
var animSpeed = 0;
var animDelay = 0;
var working = 0;
var items = 0;

function logs() {
    "use strict";
    console.log('id: ' + id);
    console.log('-----');
    console.log('animSpeed: ' + animSpeed);
    console.log('-----');
    console.log('animDelay: ' + animDelay);
    console.log('-----');
    console.log('working: ' + working);
    console.log('==============');
}

function rollDown(items, id) {
    "use strict";
    var dist = $('li').eq(id).outerHeight(), slideDown = {'margin-top' : '+=' + dist + 'px'};
    console.log('items: ' + items + ' & id: ' + id);
    if (id <= items) {
        if (id === 0) {
            $('#toggle').html('Hide &uarr;');
        }
        $('li').not($('li').eq(id).prevAll()).delay(animDelay).animate(slideDown, animSpeed);
        id++;
        logs();
        rollDown(items, id);
    } else {
        console.log('herp derp');
        logs();
    }
}

function getVals() {
    "use strict";
    animSpeed = $('#speed').val();
    animDelay = $('#delay').val();
}

function resetPosition() {
    "use strict";
    $('li').stop().css('margin-top', 0);
    id = 0;
    working = 0;
    $('#toggle').html('Show &darr;');
}

$(function () {
    "use strict";
    $('header > a').click(function () {
        if (id === 0 && working === 0) {
            getVals();
            items = $('ul').children().length;
            var z;
            for (z = 0; z < items; z++) {
                $('li').eq(z).css('z-index', items - z);
            }
            working = 1;
            rollDown(items, id);
        } else if (id !== 0) {
            resetPosition();
            alert('!!');
        }
        return false;
    });
});

Here is what my console prints out:

items: 6 & id: 0
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 1
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 2
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 3
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 4
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 5
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 6
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
items: 6 & id: 7
herp derp
id: 0
-----
animSpeed: 410
-----
animDelay: 20
-----
working: 1
==============
  • 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-31T03:10:26+00:00Added an answer on May 31, 2026 at 3:10 am

    You have id as a parameter defined in the rollDown method signature. If you remove it, your global variable will update properly.

    From:

    function rollDown(items, id) {
    

    To:

    function rollDown(items) {
    

    You may also want to remove items, as that is also defined in the global namespace.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.