2

Namaste!

My simple issue is that $sortedData becomes undefined in the following code upon execution:

(function($) {
              $.fn.shuffle = function (){
                  var i = this.length, j, temp;
                  if ( i == 0 ) { return; }
                  while ( --i ) {
                      j = Math.floor( Math.random() * ( i + 1 ) );
                      temp = this[i];
                      this[i] = this[j];
                      this[j] = temp;
                  }
              };
            })(jQuery);

// DOMContentLoaded
            $(function() {
              // get the first collection
              var $cards = $('#cards');
              // clone cards to get a second collection
              var $data = $cards.clone();
              // call Quicksand when button clicked
              $('#shuffle').click(function(e) {
                // get all the list items
                var $filteredData = $data.find('li');
                // random sort (shuffling)
                var $sortedData = $filteredData.shuffle();
                // finally, call quicksand
                $cards.quicksand($sortedData, {
                  duration: 600,
                  easing: 'easeInOutQuad'
                });
              });

            });

How this is called: I have a button that, when clicked, executes the above code.

I've checked the values in the shuffle function, and prior to the call to the shuffle function, but, when the shuffle function returns, $sortedData is undefined.

The error is probably a noobish one, but, I can't see it.

Thank you for your input!

1
  • 1
    You are missing a return statement in the shuffle method Commented Nov 21, 2011 at 17:40

1 Answer 1

3

Your "shuffle" function does not return anything, but you're treating it as if it does. It appears to shuffle in-place.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.