{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/283","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/283/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/283/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/283/events","html_url":"https://github.com/ga-wdi-boston/game-project/issues/283","id":177772795,"number":283,"title":"PATCH - update game only works for player O","user":{"login":"knoddin","id":20615587,"avatar_url":"https://avatars.githubusercontent.com/u/20615587?v=3","gravatar_id":"","url":"https://api.github.com/users/knoddin","html_url":"https://github.com/knoddin","followers_url":"https://api.github.com/users/knoddin/followers","following_url":"https://api.github.com/users/knoddin/following{/other_user}","gists_url":"https://api.github.com/users/knoddin/gists{/gist_id}","starred_url":"https://api.github.com/users/knoddin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knoddin/subscriptions","organizations_url":"https://api.github.com/users/knoddin/orgs","repos_url":"https://api.github.com/users/knoddin/repos","events_url":"https://api.github.com/users/knoddin/events{/privacy}","received_events_url":"https://api.github.com/users/knoddin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-19T12:35:27Z","updated_at":"2016-09-19T12:59:16Z","closed_at":null,"body":"I would like to call my api.updateGame function after each player's turn. It seems that I can successfully patch to the server after player O's turn, but not after player X. If I include the code after player X, I am unable to create a new game (which means I can't update a game). Here is the code, which I currently have commented out for player X: \r\n\r\n```js\r\nconst onClick = function(){\r\n  let tileClicked = $(this).attr('data-id');\r\n  if (turns % 2 === 0) {\r\n    player = 'x';\r\n    this.innerHTML = '<img src = http://i.imgur.com/XvpQ5p5s.png>';\r\n    gameBoard.insert(tileClicked, \"X\");\r\n    turns++;\r\n    // api.updateGame(tileClicked, player, over);\r\n      // .done(ui.updateGameSuccess)\r\n      // .fail(ui.failure);\r\n    winCondition(gameBoard);\r\n  }\r\n  else {\r\n    player = 'o';\r\n    this.innerHTML = '<img src = http://i.imgur.com/bPWrglqs.png>';\r\n    gameBoard.insert(tileClicked, \"O\");\r\n    turns++;\r\n    api.updateGame(tileClicked, player, over)\r\n      .done(ui.updateGameSuccess)\r\n      .fail(ui.failure);\r\n    winCondition(gameBoard);\r\n  }\r\n};\r\n```\r\nIs there a way to place this so it targets both? Below, also, is my onNewGame code:\r\n\r\n```js\r\nconst onNewGame = function(event){\r\n  event.preventDefault();\r\n  clearBoard();\r\n  let data = {};\r\n    api.newGame(data)\r\n    .done(ui.newGameSuccess)\r\n    .fail(ui.failure);\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/comments/247986076","html_url":"https://github.com/ga-wdi-boston/game-project/issues/283#issuecomment-247986076","issue_url":"https://api.github.com/repos/ga-wdi-boston/game-project/issues/283","id":247986076,"user":{"login":"jrhorn424","id":388761,"avatar_url":"https://avatars.githubusercontent.com/u/388761?v=3","gravatar_id":"","url":"https://api.github.com/users/jrhorn424","html_url":"https://github.com/jrhorn424","followers_url":"https://api.github.com/users/jrhorn424/followers","following_url":"https://api.github.com/users/jrhorn424/following{/other_user}","gists_url":"https://api.github.com/users/jrhorn424/gists{/gist_id}","starred_url":"https://api.github.com/users/jrhorn424/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrhorn424/subscriptions","organizations_url":"https://api.github.com/users/jrhorn424/orgs","repos_url":"https://api.github.com/users/jrhorn424/repos","events_url":"https://api.github.com/users/jrhorn424/events{/privacy}","received_events_url":"https://api.github.com/users/jrhorn424/received_events","type":"User","site_admin":false},"created_at":"2016-09-19T12:59:16Z","updated_at":"2016-09-19T12:59:16Z","body":"Move duplicated lines out of the `if` block. Instead of using `this.innerHTML`, use `$(this).html`.\r\n\r\nWhat's a duplicated line? Well, you're going to fire an API request no matter what, so you should move that outside of the control flow and have it fire regardless of whose turn it is. You can set the player in the control flow, but you don't have to fire the API call there."}}
{"actor":{"display_login":"jrhorn424"}}