{"action":"created","comment":{"url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/comments/187419209","pull_request_review_id":119196009,"id":187419209,"diff_hunk":"@@ -1 +1,203 @@\n // Code your JavaScript / jQuery solution here\n+var turn;\n+var gameId;\n+$(document).ready(initialize)\n+\n+function initialize() {\n+  attachListeners();\n+  turn = 0;\n+  gameId = undefined;\n+}\n+\n+function player() { // X=even, Y=odd\n+  if ((turn % 2) === 0) {\n+    return \"X\"; \n+  } else {\n+    return \"O\";\n+  }\n+}\n+\n+function updateState(el) { // Pass an element to update it with the current player's symbol\n+  const x = el.attributes[0].nodeValue; // Get x coordinate (0-2)\n+  const y = el.attributes[1].nodeValue; // Get y coordinate (0-2)\n+  let square = $(`[data-x=${x}][data-y=${y}]`);\n+\n+  if (square.text() === \"\") {\n+    square.text(player());\n+    return true;\n+  } else {\n+    return false;\n+  }\n+}\n+\n+function setMessage(string) {\n+  $(\"#message\").text(string);\n+}\n+\n+function checkWinner() {\n+  let xSpots = [];\n+  let o_spots = [];\n+  let win = [\n+    [0,1,2],[0,3,6],[0,4,8],[6,4,2],[2,5,8],[6,7,8],[3,4,5],[1,4,7]\n+  ];\n+  let square;\n+\n+  for (let x = 0; x < 3; x++) {\n+    for (let y = 0; y < 3; y++) {\n+      square = $(`[data-x=${x}][data-y=${y}]`).text()\n+\n+      if (square === \"X\") {\n+        xSpots.push(x + y*3);\n+      } else if (square === \"O\") {\n+        o_spots.push(x + y*3);\n+      }\n+    }\n+  }\n+\n+  // Check each player's spots for a win combination\n+  for (let i = 0; i < win.length; i++) {\n+    if (xSpots.includes(win[i][0]) \n+      && xSpots.includes(win[i][1]) \n+      && xSpots.includes(win[i][2])) {\n+        setMessage('Player X Won!');\n+        return true;  \n+    } else if (o_spots.includes(win[i][0]) \n+      && o_spots.includes(win[i][1]) \n+      && o_spots.includes(win[i][2])) {\n+        setMessage('Player O Won!');\n+        return true;\n+    } \n+  }\n+  // -- code will only get here if no player has won ---\n+  // If board is full, it's a tie\n+  if (fullBoard()) {\n+    setMessage('Tie game.');\n+  }\n+  return false;\n+}\n+\n+function doTurn(el) {\n+  if (updateState(el)) {\n+    turn += 1;\n+  }\n+  if (checkWinner()) {\n+    saveGame();\n+    resetGame();\n+  } else if (fullBoard()) {\n+    // Must be a draw\n+    saveGame();\n+    resetGame();\n+  }\n+  /*\n+  updateState(el);\n+  turn++;\n+  */\n+}\n+\n+function attachListeners() {","path":"app/assets/javascripts/tictactoe.js","position":97,"original_position":97,"commit_id":"cce151dc2166011d3c0d529f6f58e99c1e01cf30","original_commit_id":"cce151dc2166011d3c0d529f6f58e99c1e01cf30","user":{"login":"weezwo","id":19954790,"avatar_url":"https://avatars3.githubusercontent.com/u/19954790?v=4","gravatar_id":"","url":"https://api.github.com/users/weezwo","html_url":"https://github.com/weezwo","followers_url":"https://api.github.com/users/weezwo/followers","following_url":"https://api.github.com/users/weezwo/following{/other_user}","gists_url":"https://api.github.com/users/weezwo/gists{/gist_id}","starred_url":"https://api.github.com/users/weezwo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weezwo/subscriptions","organizations_url":"https://api.github.com/users/weezwo/orgs","repos_url":"https://api.github.com/users/weezwo/repos","events_url":"https://api.github.com/users/weezwo/events{/privacy}","received_events_url":"https://api.github.com/users/weezwo/received_events","type":"User","site_admin":false},"body":"It looks like you are calling `attachListeners` in your `document.ready`, but you have 1 or more listeners outside of that function.\r\n\r\n```javascript\r\n$(document).ready(function() {\r\n  attachListeners();\r\n})\r\n\r\nfunction attachListeners() {\r\n  $('td').on('click', function() {\r\n    if (!$.text(this) && !checkWinner()) {\r\n      doTurn(this);\r\n    }\r\n  });\r\n\r\n  $('#save').on('click', () => saveGame());\r\n  $('#previous').on('click', () => showPreviousGames());\r\n  $('#clear').on('click', () => resetBoard());\r\n}\r\n```\r\n","created_at":"2018-05-10T18:33:33Z","updated_at":"2018-05-10T18:35:07Z","html_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391#discussion_r187419209","pull_request_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/comments/187419209"},"html":{"href":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391#discussion_r187419209"},"pull_request":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391"}}},"pull_request":{"url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391","id":181964135,"html_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391","diff_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391.diff","patch_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391.patch","issue_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/391","number":391,"state":"open","locked":false,"title":"Done","user":{"login":"dtow55","id":28773477,"avatar_url":"https://avatars2.githubusercontent.com/u/28773477?v=4","gravatar_id":"","url":"https://api.github.com/users/dtow55","html_url":"https://github.com/dtow55","followers_url":"https://api.github.com/users/dtow55/followers","following_url":"https://api.github.com/users/dtow55/following{/other_user}","gists_url":"https://api.github.com/users/dtow55/gists{/gist_id}","starred_url":"https://api.github.com/users/dtow55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtow55/subscriptions","organizations_url":"https://api.github.com/users/dtow55/orgs","repos_url":"https://api.github.com/users/dtow55/repos","events_url":"https://api.github.com/users/dtow55/events{/privacy}","received_events_url":"https://api.github.com/users/dtow55/received_events","type":"User","site_admin":false},"body":null,"created_at":"2018-04-16T19:26:31Z","updated_at":"2018-05-10T18:35:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e06184d55cdd4ed91b95c09aa0f3df022a30286","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391/commits","review_comments_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391/comments","review_comment_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/comments{/number}","comments_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/391/comments","statuses_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/statuses/cce151dc2166011d3c0d529f6f58e99c1e01cf30","head":{"label":"dtow55:master","ref":"master","sha":"cce151dc2166011d3c0d529f6f58e99c1e01cf30","user":{"login":"dtow55","id":28773477,"avatar_url":"https://avatars2.githubusercontent.com/u/28773477?v=4","gravatar_id":"","url":"https://api.github.com/users/dtow55","html_url":"https://github.com/dtow55","followers_url":"https://api.github.com/users/dtow55/followers","following_url":"https://api.github.com/users/dtow55/following{/other_user}","gists_url":"https://api.github.com/users/dtow55/gists{/gist_id}","starred_url":"https://api.github.com/users/dtow55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtow55/subscriptions","organizations_url":"https://api.github.com/users/dtow55/orgs","repos_url":"https://api.github.com/users/dtow55/repos","events_url":"https://api.github.com/users/dtow55/events{/privacy}","received_events_url":"https://api.github.com/users/dtow55/received_events","type":"User","site_admin":false},"repo":{"id":129486042,"name":"js-tictactoe-rails-api-v-000","full_name":"dtow55/js-tictactoe-rails-api-v-000","owner":{"login":"dtow55","id":28773477,"avatar_url":"https://avatars2.githubusercontent.com/u/28773477?v=4","gravatar_id":"","url":"https://api.github.com/users/dtow55","html_url":"https://github.com/dtow55","followers_url":"https://api.github.com/users/dtow55/followers","following_url":"https://api.github.com/users/dtow55/following{/other_user}","gists_url":"https://api.github.com/users/dtow55/gists{/gist_id}","starred_url":"https://api.github.com/users/dtow55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtow55/subscriptions","organizations_url":"https://api.github.com/users/dtow55/orgs","repos_url":"https://api.github.com/users/dtow55/repos","events_url":"https://api.github.com/users/dtow55/events{/privacy}","received_events_url":"https://api.github.com/users/dtow55/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dtow55/js-tictactoe-rails-api-v-000","description":null,"fork":true,"url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000","forks_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/forks","keys_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/teams","hooks_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/hooks","issue_events_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/issues/events{/number}","events_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/events","assignees_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/assignees{/user}","branches_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/branches{/branch}","tags_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/tags","blobs_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/git/refs{/sha}","trees_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/statuses/{sha}","languages_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/languages","stargazers_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/stargazers","contributors_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/contributors","subscribers_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/subscribers","subscription_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/subscription","commits_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/commits{/sha}","git_commits_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/git/commits{/sha}","comments_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/comments{/number}","issue_comment_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/issues/comments{/number}","contents_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/contents/{+path}","compare_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/merges","archive_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/downloads","issues_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/issues{/number}","pulls_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/pulls{/number}","milestones_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/milestones{/number}","notifications_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/labels{/name}","releases_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/releases{/id}","deployments_url":"https://api.github.com/repos/dtow55/js-tictactoe-rails-api-v-000/deployments","created_at":"2018-04-14T05:47:00Z","updated_at":"2018-04-16T19:26:29Z","pushed_at":"2018-04-16T19:26:27Z","git_url":"git://github.com/dtow55/js-tictactoe-rails-api-v-000.git","ssh_url":"git@github.com:dtow55/js-tictactoe-rails-api-v-000.git","clone_url":"https://github.com/dtow55/js-tictactoe-rails-api-v-000.git","svn_url":"https://github.com/dtow55/js-tictactoe-rails-api-v-000","homepage":null,"size":194,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"learn-co-students:master","ref":"master","sha":"74bce8766eea264c02c2d0739ab5a035962290f6","user":{"login":"learn-co-students","id":8825476,"avatar_url":"https://avatars3.githubusercontent.com/u/8825476?v=4","gravatar_id":"","url":"https://api.github.com/users/learn-co-students","html_url":"https://github.com/learn-co-students","followers_url":"https://api.github.com/users/learn-co-students/followers","following_url":"https://api.github.com/users/learn-co-students/following{/other_user}","gists_url":"https://api.github.com/users/learn-co-students/gists{/gist_id}","starred_url":"https://api.github.com/users/learn-co-students/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learn-co-students/subscriptions","organizations_url":"https://api.github.com/users/learn-co-students/orgs","repos_url":"https://api.github.com/users/learn-co-students/repos","events_url":"https://api.github.com/users/learn-co-students/events{/privacy}","received_events_url":"https://api.github.com/users/learn-co-students/received_events","type":"Organization","site_admin":false},"repo":{"id":52471975,"name":"js-tictactoe-rails-api-v-000","full_name":"learn-co-students/js-tictactoe-rails-api-v-000","owner":{"login":"learn-co-students","id":8825476,"avatar_url":"https://avatars3.githubusercontent.com/u/8825476?v=4","gravatar_id":"","url":"https://api.github.com/users/learn-co-students","html_url":"https://github.com/learn-co-students","followers_url":"https://api.github.com/users/learn-co-students/followers","following_url":"https://api.github.com/users/learn-co-students/following{/other_user}","gists_url":"https://api.github.com/users/learn-co-students/gists{/gist_id}","starred_url":"https://api.github.com/users/learn-co-students/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learn-co-students/subscriptions","organizations_url":"https://api.github.com/users/learn-co-students/orgs","repos_url":"https://api.github.com/users/learn-co-students/repos","events_url":"https://api.github.com/users/learn-co-students/events{/privacy}","received_events_url":"https://api.github.com/users/learn-co-students/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000","description":null,"fork":false,"url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000","forks_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/forks","keys_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/keys{/key_id}","collaborators_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/teams","hooks_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/hooks","issue_events_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/events{/number}","events_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/events","assignees_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/assignees{/user}","branches_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/branches{/branch}","tags_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/tags","blobs_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/git/refs{/sha}","trees_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/git/trees{/sha}","statuses_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/statuses/{sha}","languages_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/languages","stargazers_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/stargazers","contributors_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/contributors","subscribers_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/subscribers","subscription_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/subscription","commits_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/commits{/sha}","git_commits_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/git/commits{/sha}","comments_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/comments{/number}","issue_comment_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/comments{/number}","contents_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/contents/{+path}","compare_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/compare/{base}...{head}","merges_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/merges","archive_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/downloads","issues_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues{/number}","pulls_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls{/number}","milestones_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/milestones{/number}","notifications_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/labels{/name}","releases_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/releases{/id}","deployments_url":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/deployments","created_at":"2016-02-24T20:24:11Z","updated_at":"2018-03-29T23:07:01Z","pushed_at":"2018-05-10T12:20:18Z","git_url":"git://github.com/learn-co-students/js-tictactoe-rails-api-v-000.git","ssh_url":"git@github.com:learn-co-students/js-tictactoe-rails-api-v-000.git","clone_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000.git","svn_url":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000","homepage":null,"size":172,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":451,"mirror_url":null,"archived":false,"open_issues_count":400,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":451,"open_issues":400,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391"},"html":{"href":"https://github.com/learn-co-students/js-tictactoe-rails-api-v-000/pull/391"},"issue":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/391"},"comments":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/issues/391/comments"},"review_comments":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391/comments"},"review_comment":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/pulls/391/commits"},"statuses":{"href":"https://api.github.com/repos/learn-co-students/js-tictactoe-rails-api-v-000/statuses/cce151dc2166011d3c0d529f6f58e99c1e01cf30"}},"author_association":"NONE"}}
{"actor":{"display_login":"weezwo"}}