{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/668","repository_url":"https://api.github.com/repos/ga-wdi-boston/game-project","labels_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/668/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/668/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/668/events","html_url":"https://github.com/ga-wdi-boston/game-project/issues/668","id":221970865,"number":668,"title":"Re-enable click","user":{"login":"rowlandhill","id":20341219,"avatar_url":"https://avatars0.githubusercontent.com/u/20341219?v=3","gravatar_id":"","url":"https://api.github.com/users/rowlandhill","html_url":"https://github.com/rowlandhill","followers_url":"https://api.github.com/users/rowlandhill/followers","following_url":"https://api.github.com/users/rowlandhill/following{/other_user}","gists_url":"https://api.github.com/users/rowlandhill/gists{/gist_id}","starred_url":"https://api.github.com/users/rowlandhill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowlandhill/subscriptions","organizations_url":"https://api.github.com/users/rowlandhill/orgs","repos_url":"https://api.github.com/users/rowlandhill/repos","events_url":"https://api.github.com/users/rowlandhill/events{/privacy}","received_events_url":"https://api.github.com/users/rowlandhill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-04-15T20:29:09Z","updated_at":"2017-04-17T21:09:35Z","closed_at":null,"body":"Hi!  I'm having a really hard time figuring out how to re-enable click events on my board.  I can get through an entire game, and when the game finishes, `unbind()` is triggered.  When I click the Create Game button, I have `bind()` in the function, but my click do nothing to the board.  \r\nI've read through the .bind()/.unbind() and the .on()/.off() documentation, but I'm still confused.  I'm not sure if my code is prevent those from executing, but I'm a little lost on this.  \r\n\r\nMy button is linked to createGameSuccess:\r\n\r\n```js\r\nconst createGameSuccess = (response) => {\r\n  console.log('response is', response)\r\n  gameLogic.resetBoard()\r\n  gameLogic.changeUiMessage('FIGHT!')\r\n  $('#container').removeClass('hidden')\r\n  $('#alert').removeClass('hidden')\r\n}\r\n```\r\n\r\nHere is where the `resetBoard()` and `changeUiMessage()` functions are called\r\n\r\n```js\r\n'use strict'\r\n\r\nlet turn = 'X'\r\nlet win = false\r\nlet moves = 0\r\nlet gameArray = ['', '', '', '', '', '', '', '', '']\r\nconst winningCombos = [\r\n  [0, 1, 2],\r\n  [3, 4, 5],\r\n  [6, 7, 8],\r\n  [0, 3, 6],\r\n  [1, 4, 7],\r\n  [2, 5, 8],\r\n  [0, 4, 8],\r\n  [2, 4, 6]\r\n]\r\n\r\nconst changeAlert = (txt) => {\r\n  const element = $('#alert')[0]\r\n  $(element).text(txt)\r\n}\r\n\r\nconst changeUiMessage = (txt) => {\r\n  const uimessage = $('#ui-message')[0]\r\n  $(uimessage).text(txt)\r\n}\r\n\r\nconst startGame = () => {\r\n  changeAlert(turn + ' always starts first')\r\n}\r\n// when a square is clicked, check to see what is in the square\r\n// if a turn has been played, change alert to pick another square\r\n\r\n$('td.square').on('click', function () {\r\n  if ($(this)[0].innerHTML === '') {\r\n    $(this).text(turn)\r\n    gameArray[($(this).data('square'))] = turn\r\n    console.log(gameArray)\r\n    winnerCheck()\r\n  } else {\r\n    changeAlert('pick another square, dummy!')\r\n  }\r\n})\r\n\r\nconst endGame = () => {\r\n  if (moves === 9 && win === false)\r\n    gameDraw()\r\n  else {\r\n    changeAlert(turn + ' wins!')\r\n    $('td.square').off('click')\r\n  }\r\n}\r\n\r\nconst resetBoard = () => {\r\n  startGame()\r\n  gameArray = ['', '', '', '', '', '', '', '', '']\r\n  turn = 'X'\r\n  moves = 0\r\n  win = false\r\n  $('td.square').on('click', startGame())\r\n  $('td.square').text('')\r\n}\r\n\r\nconst gameDraw = () => {\r\n  changeAlert('a tie? boooooo! go home and think about what you\\'ve done.')\r\n  $('td.square').unbind('click')\r\n}\r\n\r\nconst changeTurn = () => {\r\n  if (turn === 'X') {\r\n    turn = 'O'\r\n  } else {\r\n    turn = 'X'\r\n  }\r\n  moves += 1\r\n  console.log(moves)\r\n  changeAlert('it\\'s ' + turn + '\\'s turn now')\r\n}\r\n\r\nconst winnerCheck = function () {\r\n  if ($('td.square')[0].innerHTML === $('td.square')[1].innerHTML && $('td.square')[1].innerHTML === $('td.square')[2].innerHTML && $('td.square')[0].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[3].innerHTML === $('td.square')[4].innerHTML && $('td.square')[4].innerHTML === $('td.square')[5].innerHTML && $('td.square')[3].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[6].innerHTML === $('td.square')[7].innerHTML && $('td.square')[7].innerHTML === $('td.square')[8].innerHTML && $('td.square')[6].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[0].innerHTML === $('td.square')[3].innerHTML && $('td.square')[3].innerHTML === $('td.square')[6].innerHTML && $('td.square')[0].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[1].innerHTML === $('td.square')[4].innerHTML && $('td.square')[4].innerHTML === $('td.square')[7].innerHTML && $('td.square')[1].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[2].innerHTML === $('td.square')[5].innerHTML && $('td.square')[5].innerHTML === $('td.square')[8].innerHTML && $('td.square')[2].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[0].innerHTML === $('td.square')[4].innerHTML && $('td.square')[4].innerHTML === $('td.square')[8].innerHTML && $('td.square')[0].innerHTML)\r\n    win = true\r\n  else if ($('td.square')[2].innerHTML === $('td.square')[4].innerHTML && $('td.square')[4].innerHTML === $('td.square')[6].innerHTML && $('td.square')[2].innerHTML)\r\n    win = true\r\n  else (\r\n    changeTurn()\r\n  )\r\n  if (win === true || moves === 9) {\r\n    return endGame()\r\n  }\r\n}\r\n\r\n// this needs to be uncommented when you get to UI\r\n\r\n// $('#reset').on('submit', function () {\r\n//   event.preventDefault()\r\n//   console.log('button test')\r\n//   jQuery('td.square').html('')\r\n//   jQuery('#alert').html('')\r\n//   $('td.square').bind()\r\n// })\r\n\r\nmodule.exports = {\r\n  changeAlert,\r\n  changeTurn,\r\n  startGame,\r\n  winnerCheck,\r\n  endGame,\r\n  gameDraw,\r\n  changeUiMessage,\r\n  resetBoard\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/comments/294593811","html_url":"https://github.com/ga-wdi-boston/game-project/issues/668#issuecomment-294593811","issue_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/668","id":294593811,"user":{"login":"MicFin","id":5384023,"avatar_url":"https://avatars0.githubusercontent.com/u/5384023?v=3","gravatar_id":"","url":"https://api.github.com/users/MicFin","html_url":"https://github.com/MicFin","followers_url":"https://api.github.com/users/MicFin/followers","following_url":"https://api.github.com/users/MicFin/following{/other_user}","gists_url":"https://api.github.com/users/MicFin/gists{/gist_id}","starred_url":"https://api.github.com/users/MicFin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MicFin/subscriptions","organizations_url":"https://api.github.com/users/MicFin/orgs","repos_url":"https://api.github.com/users/MicFin/repos","events_url":"https://api.github.com/users/MicFin/events{/privacy}","received_events_url":"https://api.github.com/users/MicFin/received_events","type":"User","site_admin":false},"created_at":"2017-04-17T21:09:35Z","updated_at":"2017-04-17T21:09:35Z","body":"I think removing the board until the user clicks `New Game` again is a fine solution."}}
{"actor":{"display_login":"MicFin"}}