Cannot read property 'length' of undefined

Description of the problem: I’m trying to shuffle an array and I keep getting the error Cannot read property ‘length’ of undefined for the line shuffle(gr). Does anybody have an idea as why that might be?
It seems as though it cannot computer gr length because it doesn’t consider the variable gr as an array…


drop the “var” from the start of each variable definition, in fact drop the “var participant, CB, bl, gr” line altogether and you should be fine. The issue is that begin experiment is a separate function from wherever the rest of the code is being executed, and using “var” like that specifies it as local scope rather than global scope. Removing var automatically allows it to be defined with global scope, allowing other functions to access it.

It worked brillantly! Thanks!