{"action":"created","comment":{"url":"https://api.github.com/repos/fpfarina/startup/pulls/comments/61246342","id":61246342,"diff_hunk":"@@ -0,0 +1,388 @@\n+'use strict';\n+\n+/* The global variable Clicks advices how many times the user has pressed the joke button. Tt's used in EX 6, to\n+ * control the Time  Out error. */\n+var Clicks = 0;\n+\n+/* The global variable JSuccess it's used at exercise 6, to determinate if the server has answered and avoid\n+ * showing old \"time out\" errors. */\n+var JSuccess = false;\n+\n+/* It will clear all the content of a DOM given node.\n+*  Method: Just looks for all childNodes of a given node and delete one by one.*/\n+function removeAllChildNodes(node){\n+    while ( node.hasChildNodes() ) {\n+        node.removeChild(node.firstChild);\n+    }\n+}\n+\n+/* EX 6 - This function uses XMLHttpRequest, to get a joke from the given source.\n+ * This function it's really basic, in the EX 1.7 i've make a better implementation.\n+ * In case of an erro ocurr, it can't determinate what kind of error it's happening, \n+ * it will only send a \"Time out error\".\n+ * Any new click on the button will kill the last call. To make this happen, i use the global variable Clicks.\n+ * If (callId) is equal to (Click), the function will show a joke or an error because it's match with the last\n+ * click, but if not, it'll do nothing. I know it's not efficient.*/\n+function tellMeAJoke(){\n+    JSuccess = false; ///* Set the global variable JSuccess to false. Tt's used\n+    // to determinate if the server has answered and avoid showing old \"time out\" errors.\n+    // If JSuccess = true, the server has answered. If not, the time out error, will be call.\n+    var callId = Clicks;\n+    var req = new XMLHttpRequest(); //A new HttpRequest object\n+    req.open (\"GET\", \"http://api.icndb.com/jokes/random\", true); //Configuration: GET - src - Async\n+    setTimeout(function(){\n+        if (Clicks == callId && JSuccess == false){ //Is it the last call and now answer yet?\n+            changeColor(\"red\");\n+            changeAdvice(\"ERROR: Time OUT!!\");\n+        }\n+    },3000);\n+    req.addEventListener(\"load\", function(){ // When the server answer --> show the joke!!.\n+        if (Clicks == callId){ //Is it the last call?\n+            console.log(\"HERE\" + Clicks);\n+            showJoke(req); // This function it's the one that show JOKES. It's used by exercises 6 and 7.\n+            changeColor(\"green\");\n+            changeAdvice(\"JOKE SUCCESS!!\");\n+            JSuccess = true;\n+        }\n+    });\n+    req.send(null); // send the HttpRequest.\n+}\n+\n+/* EX 7 (KEY) and 6\n+ * function showJoke(reqJSON)\n+ * where reqJSON -> It's a JSON object\n+ *  This function takes a JSON answer of the HttpRequest, and show it in the HTML Document, modifying the DOM.\n+*/\n+function showJoke (reqJSON){\n+    if (reqJSON.status < 400){ // if < 400 ->> Success!\n+        var reqParse = JSON.parse(reqJSON.responseText); // parse the Json answer\n+             /*Different commands i tried to understand the structure of the requested JSON object -\n+             * i don't delete it in case somebody seeing the code wanna to know its structure.\n+                 console.log(reqJSON.status, reqJSON.statusText); // Req status\n+                 console.log(reqJSON.responseText); // Devolution\n+                 console.log(reqParse); // [type (string), value (object)]\n+                 console.log(reqParse.value); // [id (integer), joke(string), categories(array)]\n+                 console.log(reqParse.value.categories); // categories elements\n+             */\n+        var elem = document.createElement(\"p\"); // new element <p>\n+        var cont = document.createTextNode(reqParse.value[\"joke\"]); // new element <p> content\n+        elem.appendChild(cont); // insert node cont in node elem <p>\n+        var where = document.getElementById(\"hide\"); // looking for the section where i will work\n+        removeAllChildNodes(where); // this function remove all childs of a node, in this case, it will delete all the content\n+        where.appendChild(elem.appendChild(cont)); // insert the <p> element with its content in the section \"hide\"\n+        where.style.fontSize= \"20px\"; // Some style for a better watching","path":"01-JS-DOM-APIs/js/index.js","position":73,"original_position":73,"commit_id":"78e615dc3176430f25c7d369ae38cca8aaa28130","original_commit_id":"78e615dc3176430f25c7d369ae38cca8aaa28130","user":{"login":"troianoandres","id":8448246,"avatar_url":"https://avatars.githubusercontent.com/u/8448246?v=3","gravatar_id":"","url":"https://api.github.com/users/troianoandres","html_url":"https://github.com/troianoandres","followers_url":"https://api.github.com/users/troianoandres/followers","following_url":"https://api.github.com/users/troianoandres/following{/other_user}","gists_url":"https://api.github.com/users/troianoandres/gists{/gist_id}","starred_url":"https://api.github.com/users/troianoandres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troianoandres/subscriptions","organizations_url":"https://api.github.com/users/troianoandres/orgs","repos_url":"https://api.github.com/users/troianoandres/repos","events_url":"https://api.github.com/users/troianoandres/events{/privacy}","received_events_url":"https://api.github.com/users/troianoandres/received_events","type":"User","site_admin":false},"body":"This is fine but I'd suggest for next time to use a class instead and set the styling to that class.","created_at":"2016-04-27T12:12:50Z","updated_at":"2016-04-27T12:12:50Z","html_url":"https://github.com/fpfarina/startup/pull/3#discussion_r61246342","pull_request_url":"https://api.github.com/repos/fpfarina/startup/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/comments/61246342"},"html":{"href":"https://github.com/fpfarina/startup/pull/3#discussion_r61246342"},"pull_request":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/fpfarina/startup/pulls/3","id":67538778,"html_url":"https://github.com/fpfarina/startup/pull/3","diff_url":"https://github.com/fpfarina/startup/pull/3.diff","patch_url":"https://github.com/fpfarina/startup/pull/3.patch","issue_url":"https://api.github.com/repos/fpfarina/startup/issues/3","number":3,"state":"open","locked":false,"title":"Topic 1 - JavaScript and DOM APIs","user":{"login":"fpfarina","id":18471874,"avatar_url":"https://avatars.githubusercontent.com/u/18471874?v=3","gravatar_id":"","url":"https://api.github.com/users/fpfarina","html_url":"https://github.com/fpfarina","followers_url":"https://api.github.com/users/fpfarina/followers","following_url":"https://api.github.com/users/fpfarina/following{/other_user}","gists_url":"https://api.github.com/users/fpfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/fpfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpfarina/subscriptions","organizations_url":"https://api.github.com/users/fpfarina/orgs","repos_url":"https://api.github.com/users/fpfarina/repos","events_url":"https://api.github.com/users/fpfarina/events{/privacy}","received_events_url":"https://api.github.com/users/fpfarina/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-22T16:30:51Z","updated_at":"2016-04-27T12:12:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"212a5cac0f3df10a4193ffb0c826d73bfc3256e0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fpfarina/startup/pulls/3/commits","review_comments_url":"https://api.github.com/repos/fpfarina/startup/pulls/3/comments","review_comment_url":"https://api.github.com/repos/fpfarina/startup/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fpfarina/startup/issues/3/comments","statuses_url":"https://api.github.com/repos/fpfarina/startup/statuses/78e615dc3176430f25c7d369ae38cca8aaa28130","head":{"label":"fpfarina:topic1","ref":"topic1","sha":"78e615dc3176430f25c7d369ae38cca8aaa28130","user":{"login":"fpfarina","id":18471874,"avatar_url":"https://avatars.githubusercontent.com/u/18471874?v=3","gravatar_id":"","url":"https://api.github.com/users/fpfarina","html_url":"https://github.com/fpfarina","followers_url":"https://api.github.com/users/fpfarina/followers","following_url":"https://api.github.com/users/fpfarina/following{/other_user}","gists_url":"https://api.github.com/users/fpfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/fpfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpfarina/subscriptions","organizations_url":"https://api.github.com/users/fpfarina/orgs","repos_url":"https://api.github.com/users/fpfarina/repos","events_url":"https://api.github.com/users/fpfarina/events{/privacy}","received_events_url":"https://api.github.com/users/fpfarina/received_events","type":"User","site_admin":false},"repo":{"id":56525989,"name":"startup","full_name":"fpfarina/startup","owner":{"login":"fpfarina","id":18471874,"avatar_url":"https://avatars.githubusercontent.com/u/18471874?v=3","gravatar_id":"","url":"https://api.github.com/users/fpfarina","html_url":"https://github.com/fpfarina","followers_url":"https://api.github.com/users/fpfarina/followers","following_url":"https://api.github.com/users/fpfarina/following{/other_user}","gists_url":"https://api.github.com/users/fpfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/fpfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpfarina/subscriptions","organizations_url":"https://api.github.com/users/fpfarina/orgs","repos_url":"https://api.github.com/users/fpfarina/repos","events_url":"https://api.github.com/users/fpfarina/events{/privacy}","received_events_url":"https://api.github.com/users/fpfarina/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fpfarina/startup","description":"Basic folder structure","fork":true,"url":"https://api.github.com/repos/fpfarina/startup","forks_url":"https://api.github.com/repos/fpfarina/startup/forks","keys_url":"https://api.github.com/repos/fpfarina/startup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fpfarina/startup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fpfarina/startup/teams","hooks_url":"https://api.github.com/repos/fpfarina/startup/hooks","issue_events_url":"https://api.github.com/repos/fpfarina/startup/issues/events{/number}","events_url":"https://api.github.com/repos/fpfarina/startup/events","assignees_url":"https://api.github.com/repos/fpfarina/startup/assignees{/user}","branches_url":"https://api.github.com/repos/fpfarina/startup/branches{/branch}","tags_url":"https://api.github.com/repos/fpfarina/startup/tags","blobs_url":"https://api.github.com/repos/fpfarina/startup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fpfarina/startup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fpfarina/startup/git/refs{/sha}","trees_url":"https://api.github.com/repos/fpfarina/startup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fpfarina/startup/statuses/{sha}","languages_url":"https://api.github.com/repos/fpfarina/startup/languages","stargazers_url":"https://api.github.com/repos/fpfarina/startup/stargazers","contributors_url":"https://api.github.com/repos/fpfarina/startup/contributors","subscribers_url":"https://api.github.com/repos/fpfarina/startup/subscribers","subscription_url":"https://api.github.com/repos/fpfarina/startup/subscription","commits_url":"https://api.github.com/repos/fpfarina/startup/commits{/sha}","git_commits_url":"https://api.github.com/repos/fpfarina/startup/git/commits{/sha}","comments_url":"https://api.github.com/repos/fpfarina/startup/comments{/number}","issue_comment_url":"https://api.github.com/repos/fpfarina/startup/issues/comments{/number}","contents_url":"https://api.github.com/repos/fpfarina/startup/contents/{+path}","compare_url":"https://api.github.com/repos/fpfarina/startup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fpfarina/startup/merges","archive_url":"https://api.github.com/repos/fpfarina/startup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fpfarina/startup/downloads","issues_url":"https://api.github.com/repos/fpfarina/startup/issues{/number}","pulls_url":"https://api.github.com/repos/fpfarina/startup/pulls{/number}","milestones_url":"https://api.github.com/repos/fpfarina/startup/milestones{/number}","notifications_url":"https://api.github.com/repos/fpfarina/startup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fpfarina/startup/labels{/name}","releases_url":"https://api.github.com/repos/fpfarina/startup/releases{/id}","deployments_url":"https://api.github.com/repos/fpfarina/startup/deployments","created_at":"2016-04-18T17:01:06Z","updated_at":"2016-03-16T13:20:22Z","pushed_at":"2016-04-26T22:06:51Z","git_url":"git://github.com/fpfarina/startup.git","ssh_url":"git@github.com:fpfarina/startup.git","clone_url":"https://github.com/fpfarina/startup.git","svn_url":"https://github.com/fpfarina/startup","homepage":null,"size":1795,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"fpfarina:master","ref":"master","sha":"baa64d426d5d0e1f54d913315c4b85e1bdecdbbf","user":{"login":"fpfarina","id":18471874,"avatar_url":"https://avatars.githubusercontent.com/u/18471874?v=3","gravatar_id":"","url":"https://api.github.com/users/fpfarina","html_url":"https://github.com/fpfarina","followers_url":"https://api.github.com/users/fpfarina/followers","following_url":"https://api.github.com/users/fpfarina/following{/other_user}","gists_url":"https://api.github.com/users/fpfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/fpfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpfarina/subscriptions","organizations_url":"https://api.github.com/users/fpfarina/orgs","repos_url":"https://api.github.com/users/fpfarina/repos","events_url":"https://api.github.com/users/fpfarina/events{/privacy}","received_events_url":"https://api.github.com/users/fpfarina/received_events","type":"User","site_admin":false},"repo":{"id":56525989,"name":"startup","full_name":"fpfarina/startup","owner":{"login":"fpfarina","id":18471874,"avatar_url":"https://avatars.githubusercontent.com/u/18471874?v=3","gravatar_id":"","url":"https://api.github.com/users/fpfarina","html_url":"https://github.com/fpfarina","followers_url":"https://api.github.com/users/fpfarina/followers","following_url":"https://api.github.com/users/fpfarina/following{/other_user}","gists_url":"https://api.github.com/users/fpfarina/gists{/gist_id}","starred_url":"https://api.github.com/users/fpfarina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpfarina/subscriptions","organizations_url":"https://api.github.com/users/fpfarina/orgs","repos_url":"https://api.github.com/users/fpfarina/repos","events_url":"https://api.github.com/users/fpfarina/events{/privacy}","received_events_url":"https://api.github.com/users/fpfarina/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fpfarina/startup","description":"Basic folder structure","fork":true,"url":"https://api.github.com/repos/fpfarina/startup","forks_url":"https://api.github.com/repos/fpfarina/startup/forks","keys_url":"https://api.github.com/repos/fpfarina/startup/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fpfarina/startup/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fpfarina/startup/teams","hooks_url":"https://api.github.com/repos/fpfarina/startup/hooks","issue_events_url":"https://api.github.com/repos/fpfarina/startup/issues/events{/number}","events_url":"https://api.github.com/repos/fpfarina/startup/events","assignees_url":"https://api.github.com/repos/fpfarina/startup/assignees{/user}","branches_url":"https://api.github.com/repos/fpfarina/startup/branches{/branch}","tags_url":"https://api.github.com/repos/fpfarina/startup/tags","blobs_url":"https://api.github.com/repos/fpfarina/startup/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fpfarina/startup/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fpfarina/startup/git/refs{/sha}","trees_url":"https://api.github.com/repos/fpfarina/startup/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fpfarina/startup/statuses/{sha}","languages_url":"https://api.github.com/repos/fpfarina/startup/languages","stargazers_url":"https://api.github.com/repos/fpfarina/startup/stargazers","contributors_url":"https://api.github.com/repos/fpfarina/startup/contributors","subscribers_url":"https://api.github.com/repos/fpfarina/startup/subscribers","subscription_url":"https://api.github.com/repos/fpfarina/startup/subscription","commits_url":"https://api.github.com/repos/fpfarina/startup/commits{/sha}","git_commits_url":"https://api.github.com/repos/fpfarina/startup/git/commits{/sha}","comments_url":"https://api.github.com/repos/fpfarina/startup/comments{/number}","issue_comment_url":"https://api.github.com/repos/fpfarina/startup/issues/comments{/number}","contents_url":"https://api.github.com/repos/fpfarina/startup/contents/{+path}","compare_url":"https://api.github.com/repos/fpfarina/startup/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fpfarina/startup/merges","archive_url":"https://api.github.com/repos/fpfarina/startup/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fpfarina/startup/downloads","issues_url":"https://api.github.com/repos/fpfarina/startup/issues{/number}","pulls_url":"https://api.github.com/repos/fpfarina/startup/pulls{/number}","milestones_url":"https://api.github.com/repos/fpfarina/startup/milestones{/number}","notifications_url":"https://api.github.com/repos/fpfarina/startup/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fpfarina/startup/labels{/name}","releases_url":"https://api.github.com/repos/fpfarina/startup/releases{/id}","deployments_url":"https://api.github.com/repos/fpfarina/startup/deployments","created_at":"2016-04-18T17:01:06Z","updated_at":"2016-03-16T13:20:22Z","pushed_at":"2016-04-26T22:06:51Z","git_url":"git://github.com/fpfarina/startup.git","ssh_url":"git@github.com:fpfarina/startup.git","clone_url":"https://github.com/fpfarina/startup.git","svn_url":"https://github.com/fpfarina/startup","homepage":null,"size":1795,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/3"},"html":{"href":"https://github.com/fpfarina/startup/pull/3"},"issue":{"href":"https://api.github.com/repos/fpfarina/startup/issues/3"},"comments":{"href":"https://api.github.com/repos/fpfarina/startup/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fpfarina/startup/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/fpfarina/startup/statuses/78e615dc3176430f25c7d369ae38cca8aaa28130"}}}}