Hi I have this simple array inside my variable with some colors
var clr = ['#FF0000', '#0000FF', '#FFFF00', '#008000', '#FFA500', '#800080', '#ffffff'];
and then a function which should return one of those values in single quotes
function colors() {
var color;
color = "'";
color += Math.floor(Math.random() * clr.length);
color += "'";
return color;
}
this function is then called to show various colored balls
function CreateBall(x, y, vx, vy, r, s) {
this.color = colors();
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.r = r;
this.size = s;
}
However it doesn’t work? Any ideas why?
To see the full code, please look at the source here: http://dev.driz.co.uk/pool
This should fix your problem
Demo