document.addEventListener('DOMContentLoaded', startGame)

// Define your `board` object here!
var board = {
  cells: [
    { row: 0, col: 0, isMarked: false, isMine: false, hidden: true }, 
    { row: 2, col: 0, isMarked: false, isMine: false, hidden: true }, 
    { row: 1, col: 2, isMarked: false, isMine: false, hidden: true }, 
    { row: 0, col: 1, isMarked: false, isMine: false, hidden: true }, 
    { row: 0, col: 2, isMarked: false, isMine: true, hidden: true }, 
    { row: 1, col: 0, isMarked: false, isMine: true, hidden: true }, 
    { row: 1, col: 1, isMarked: false, isMine: false, hidden: true }, 
    { row: 2, col: 1, isMarked: false, isMine: false, hidden: true }, 
    { row: 2, col: 2, isMarked: false, isMine: false, hidden: true } 
  ]
}

function startGame () {
  for (var i = 0; i < board.cells.length; i++) {
    board.cells[i].surroundingMines = countSurroundingMines(board.cells[i])
  }

  document.addEventListener('click', checkForWin)
  document.addEventListener('contextmenu', checkForWin)

  // Don't remove this function call: it makes the game work!
  lib.initBoard()
}

// Define this function to look for a win condition:
//
// 1. Are all of the cells that are NOT mines visible?
// 2. Are all of the mines marked?
function checkForWin () {
  // Here, loop through 
  var remaining = board.cells
    .filter(function (cell) {
      return cell.hidden && !cell.isMarked
    })
  if (remaining.length > 0) {
    return
  }
  var incorrect = board.cells
    .filter(function (cell) {
      return cell.isMarked && !cell.isMine
    })
  if (incorrect.length > 0) {
    return
  }

  // You can use this function call to declare a winner (once you've
  // detected that they've won, that is!)
  lib.displayMessage('You win!')
}

// Define this function to count the number of mines around the cell
// (there could be as many as 8). You don't have to get the surrounding
// cells yourself! Just use `lib.getSurroundingCells`: 
//
//   var surrounding = lib.getSurroundingCells(cell.row, cell.col)
//
// It will return cell objects in an array. You should loop through 
// them, counting the number of times `cell.isMine` is true.
function countSurroundingMines (cell) {
  var surrounding = lib.getSurroundingCells(cell.row, cell.col)
  return surrounding.filter(function (adjacentCell) {
    return adjacentCell.isMine
  }).length;
}


@@ -87,16 +87,19 @@
 t here!%0A
+// 
 var boar
@@ -106,1514 +106,288 @@
 d = 
-%7B%0A  cells: %5B%0A    %7B row: 0, col: 0, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 2, col: 0, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 1, col: 2, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 0, col: 1, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 0, col: 2, isMarked: false, isMine: true, hidden: true %7D, %0A    %7B row: 1, col: 0, isMarked: false, isMine: true, hidden: true %7D, %0A    %7B row: 1, col: 1, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 2, col: 1, isMarked: false, isMine: false, hidden: true %7D, %0A    %7B row: 2, col: 2, isMarked: false, isMine: false, hidden: true %7D %0A  %5D%0A%7D%0A%0Afunction startGame () %7B%0A  for (var i = 0; i %3C board.cells.length; i++) %7B%0A    board.cells%5Bi%5D.surroundingMines = countSurroundingMines(board.cells%5Bi%5D)%0A  %7D%0A%0A  document.addEventListener('click', checkForWin)%0A  document.addEventListener('contextmenu', checkForWin)%0A%0A  // Don't remove this function call: it makes the game work!%0A  lib.initBoard()%0A%7D%0A%0A// Define this function to look for a win condition:%0A//%0A// 1. Are all of the cells that are NOT mines visible?%0A// 2. Are all of the mines marked?%0Afunction checkForWin () %7B%0A  // Here, loop through %0A  var remaining = board.cells%0A    .filter(function (cell) %7B%0A      return cell.hidden && !cell.isMarked%0A    %7D)%0A  if (remaining.length %3E 0) %7B%0A    return%0A  %7D%0A  var incorrect = board.cells%0A    .filter(function (cell) %7B%0A      return cell.isMarked && !cell.isMine%0A    %7D)%0A  if (incorrect.length %3E 0) %7B%0A    return%0A  %7D
+%0A%0Afunction startGame () %7B%0A  // Don't remove this function call: it makes the game work!%0A  lib.initBoard()%0A%7D%0A%0A// Define this function to look for a win condition:%0A//%0A// 1. Are all of the cells that are NOT mines visible?%0A// 2. Are all of the mines marked?%0Afunction checkForWin () %7B
 %0A%0A  
@@ -495,16 +495,21 @@
 at is!)%0A
+  // 
   lib.di
@@ -980,169 +980,7 @@
 ) %7B%0A
-  var surrounding = lib.getSurroundingCells(cell.row, cell.col)%0A  return surrounding.filter(function (adjacentCell) %7B%0A    return adjacentCell.isMine%0A  %7D).length;%0A
 %7D%0A%0A

Remove solution