for (... in ...) loops do not work this way in JavaScript, this should be:
for (var b = 0; b < buttons.length; b++) {
buttons[b].style.backgroundImage = "url('darkSquare.jpg')";
}
for (... in ...) actually iterates over all the "members" of the object
eg. use var x = {a: 1, b: 2, c: 3}in for(var m in x) console.log(m)will create
> a
> b
> c
it works with arrays because it considers such index elements as follows:
var x = [1,2,3];
for (var m in x) console.log(m);
> 0
> 1
> 2
because it gives you indexes as if they were members that you cannot distinguish. trap:
var x = [1,2,3];
x.stuff = 'boo!';
for (var m in x) console.log(m);
> 0
> 1
> 2
> stuff
: for (... in ...) , for (var i = 0; i < array.length; i++)
:
for (var i = 0, item = x[i]; i < x.length; item=x[++i]) {
}