{"action":"created","issue":{"url":"https://api.github.com/repos/ga-dc/project3/issues/83","labels_url":"https://api.github.com/repos/ga-dc/project3/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/ga-dc/project3/issues/83/comments","events_url":"https://api.github.com/repos/ga-dc/project3/issues/83/events","html_url":"https://github.com/ga-dc/project3/issues/83","id":121323685,"number":83,"title":"Returning true/false from a promise","user":{"login":"timothytgregg","id":14797542,"avatar_url":"https://avatars.githubusercontent.com/u/14797542?v=3","gravatar_id":"","url":"https://api.github.com/users/timothytgregg","html_url":"https://github.com/timothytgregg","followers_url":"https://api.github.com/users/timothytgregg/followers","following_url":"https://api.github.com/users/timothytgregg/following{/other_user}","gists_url":"https://api.github.com/users/timothytgregg/gists{/gist_id}","starred_url":"https://api.github.com/users/timothytgregg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timothytgregg/subscriptions","organizations_url":"https://api.github.com/users/timothytgregg/orgs","repos_url":"https://api.github.com/users/timothytgregg/repos","events_url":"https://api.github.com/users/timothytgregg/events{/privacy}","received_events_url":"https://api.github.com/users/timothytgregg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-09T19:46:07Z","updated_at":"2015-12-09T19:50:51Z","closed_at":null,"body":"Hi! \r\n\r\nA user submits a username through a form.\r\nThere is an event listener, which calls a function on the view prototype, which fires off a $.getJSON request to the github API.\r\nIf the user exists, I want this function on the prototype to return true, else false, so that we don't end up creating profiles in our database for Github profiles that don't exist.\r\n\r\nHere's the code, which I expected to return true or false, but it appears the function always returns undefined because it only returns out of the promise, not the overarching function.\r\n\r\n```js\r\nnewProfileView.prototype = {\r\n  checkProfile: function(username){\r\n    var url='https://api.github.com/search/users?q=';\r\n    .then(function(data){\r\n      if (data.total_count){\r\n        console.log(data.total_count);\r\n        boolean = true;\r\n      }\r\n      else {\r\n        console.log(data.total_count);\r\n        boolean = false;\r\n      }\r\n    });\r\n  }\r\n};\r\n```\r\n\r\nAnd then here's the event listener: \r\n\r\n```js\r\nvar newProfileView = function(profile){\r\n  var self = this;\r\n  self.$el = $(\".newProfileView\");\r\n  $(\".newProfile\").on(\"submit\", function(){\r\n    event.preventDefault();\r\n    if (self.checkProfile($('.username_input').val())){\r\n      console.log('valid user');\r\n    }\r\n    else {\r\n      console.log('invalid user');\r\n    }\r\n    //if checkProfile(username) returns truthy,\r\n    //self.createProfile();\r\n    //else 'try again'\r\n\r\n    // self.createProfile();\r\n  });\r\n};\r\n```\r\n\r\nAm I going about this the right way? Thanks!"},"comment":{"url":"https://api.github.com/repos/ga-dc/project3/issues/comments/163371228","html_url":"https://github.com/ga-dc/project3/issues/83#issuecomment-163371228","issue_url":"https://api.github.com/repos/ga-dc/project3/issues/83","id":163371228,"user":{"login":"RobertAKARobin","id":6268177,"avatar_url":"https://avatars.githubusercontent.com/u/6268177?v=3","gravatar_id":"","url":"https://api.github.com/users/RobertAKARobin","html_url":"https://github.com/RobertAKARobin","followers_url":"https://api.github.com/users/RobertAKARobin/followers","following_url":"https://api.github.com/users/RobertAKARobin/following{/other_user}","gists_url":"https://api.github.com/users/RobertAKARobin/gists{/gist_id}","starred_url":"https://api.github.com/users/RobertAKARobin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobertAKARobin/subscriptions","organizations_url":"https://api.github.com/users/RobertAKARobin/orgs","repos_url":"https://api.github.com/users/RobertAKARobin/repos","events_url":"https://api.github.com/users/RobertAKARobin/events{/privacy}","received_events_url":"https://api.github.com/users/RobertAKARobin/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T19:50:51Z","updated_at":"2015-12-09T19:50:51Z","body":"Your `.then` doesn't appear to be attached to anything here...?\r\n\r\n```js\r\nnewProfileView.prototype = {\r\n  checkProfile: function(username){\r\n    var url='https://api.github.com/search/users?q=';\r\n    .then(function(data){\r\n      if (data.total_count){\r\n        console.log(data.total_count);\r\n        boolean = true;\r\n      }\r\n      else {\r\n        console.log(data.total_count);\r\n        boolean = false;\r\n      }\r\n    });\r\n  }\r\n};\r\n```"}}