Syntax for JS to select all checkboxes

Nearly there I think - its doing something now, but is the reverse of what it should be.

When the ‘select all’ checkbox is ticked, the others are unchecked. And when it is unchecked, all the others are ticked.

Apart from when you first tick the select all.

So from page load:

  1. Nothing ticked.
  2. Check the select all checkbox - nothing happens.
  3. Uncheck the select all checkbox - all the others become checked.
  4. Check the select all checkbox - all the others become unchecked.

I tried changing

checkboxes[i].checked = source.checked;

to

checkboxes[i].unchecked = source.unchecked;

But that just broke it.