Lasers Game

by skibulk

HTML

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>

CSS

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

span {
  position: absolute;
  width: 100px;
  height: 100px;
}

.white {
  background: white;
}

.black {
  background: black;
}

JavaScript

function forFor(i, j, fn) {
  for (var ii = 0; ii < i; ii++) {
    for (var jj = 0; jj < j; jj++) {
      fn(ii, jj);
    }
  }
}

function randomBool() {
  return Math.random() >= 0.5;
}

forFor(10, 10, function(i, j) {
  var tile = $('<span/>')
    .css('top', i * 100)
    .css('left', j * 100)
    .addClass(randomBool() ? 'white' : 'black')
    .appendTo('body');
});