{"id":5270,"date":"2013-11-18T05:05:02","date_gmt":"2013-11-17T18:05:02","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5270"},"modified":"2013-11-18T05:05:02","modified_gmt":"2013-11-17T18:05:02","slug":"javascript-debug-via-firefox-and-firebug-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-debug-via-firefox-and-firebug-primer-tutorial\/","title":{"rendered":"Javascript Debug via Firefox and Firebug Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/JavascriptDebug_Firefox_Firebug.m4v\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Javascript Debug via Firefox and Firebug Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/JavascriptDebug_Firefox_Firebug.jpg\" title=\"Javascript Debug via Firefox and Firebug Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Javascript Debug via Firefox and Firebug Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s tutorial (<a target=_blank title='live run' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/\">live run<\/a>) shows some debugging techniques for Javascript work that involved the use of Firefox and its wonderful Firebug plugin (instigated via Firefox menu Tools->Web Developer->Firebug->Open Firebug), and builds on your knowledge from previous relevant <a target=_blank title='Firefox and Favourite Plugins Tutorial' href='#fafpt'>Firefox and Favourite Plugins Tutorial<\/a> as shown below.<\/p>\n<p>The background to the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/JavascriptDebug_Firefox_Firebug.m4v\">tutorial<\/a> is the finding of a <a target=_blank title='Wikipedia information regarding software bug' href='http:\/\/en.wikipedia.org\/wiki\/Software_bug'>bug<\/a> in the code for the Tic Tac Toe game presented in a few of the tutorials of this blog.   Bugs take all forms and this bug would be in the category of &#8220;it may never happen, but it is annoying leaving it this way&#8221; (ie. a player was able to click a square already picked &#8230; know none of this blog&#8217;s readers would cheat this way &#8230; surely?!).    Some bugs are much worse, in that &#8220;something doesn&#8217;t work&#8221; or &#8220;something doesn&#8217;t work, and it is crucial&#8221; (the latter being much worse, naturally).   By the way, in business, the way bugs should be treated is in a scientific way that doesn&#8217;t catastrophize things &#8230; no code is perfect &#8230; you aim for perfection, but you can stretch the situation to whatever extreme to break it one way or the other.    You&#8217;ll never achieve enough with unnecessary engineering, in the same way it is vitally important your code is functional in some way shape or form.<\/p>\n<p><strong><\/p>\n<p>Below, we&#8217;ll show you the podcast&#8217;s transcript (modified to <i>document.getElementById([the img id]).id;<\/i> and <i>cgoes=&#8221;&#8221;;<\/i> from actual podcast).<\/p>\n<p><\/strong><\/p>\n<blockquote><p>Sometimes you code something and discover<br \/>\nmuch later there is a logical weakness.<\/p>\n<p>Take the TicTacToe game mentioned often in<br \/>\nthis blog and written ages ago.<\/p>\n<p>Today found out the player could reclick a<br \/>\nsquare &#8230; da da da da &#8230; let&#8217;s debug!!<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nStep 1) Identify problem &#8230; oops<br \/>\nStep 2) As necessary get Firebug on Firefox<br \/>\n            going &#8230; already done<br \/>\nStep 3) If you are freshly familiar with<br \/>\n            Javascript, you may not need to,<br \/>\n            but here, am not, and use the<br \/>\n            Firebug-friendly Javascript<br \/>\n            console.log() method to help<br \/>\n            re-understand the code<br \/>\nStep 4) Run this new code &#8230; ah, remember<br \/>\n            now &#8230; the id of td element<br \/>\n            owning img is &#8216;t&#8217; +<br \/>\n            document.getElementById([the img id]).id;<br \/>\nStep 5) Use a global variable (var cgoes=&#8221;&#8221;;)<br \/>\n            that lasts through the length of<br \/>\n            game and is filled with moves<br \/>\n            (encased by &#8220;;&#8221;) &#8230; compare<br \/>\n            a move against cgoes and if found<br \/>\n            this move is a nono &#8230;<br \/>\n            alert(&#8220;huh?&#8221;); &#8230; change<br \/>\n            accordingly<br \/>\nStep 6) Run modified code as above &#8230; that&#8217;s<br \/>\n            better<br \/>\nStep 7) If okay we could comment out<br \/>\n            console.log(); rather than<br \/>\n            completely delete it, being as<br \/>\n            it helps future understanding,<br \/>\n            as would ideas like source<br \/>\n            control and adding your own<br \/>\n            Javascript comments within<br \/>\n            code and\/or up the top of code<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nThanks for your attention &#8230; adios &#8230; after<br \/>\n   showing you this last go &#8230; good, no<br \/>\n   console.log() nor alert() &#8230;<br \/>\n   selamat sore.<\/p>\n<\/blockquote>\n<p><strong><\/p>\n<p>This transcript, and podcast refer to some code difference references, as shown below.<\/p>\n<p><\/strong><\/p>\n<blockquote><p>Roberts-MacBook-Pro:htdocs robertmetcalfe$ diff TicTacToe_AsPer_OriginalBug.html TicTacToe_IntoInvestigating_OriginalBug.html<br \/>\n55a56,58<br \/>\n>   var paris=document.getElementById(&#8216;t&#8217; + suffix);<br \/>\n>   console.log(paris.innerHTML);<br \/>\n>   alert(paris.innerHTML);<br \/>\nRoberts-MacBook-Pro:htdocs robertmetcalfe$ diff TicTacToe_IntoInvestigating_OriginalBug.html TicTacToe_ConsoleLog.html<br \/>\n6a7<br \/>\n> var cgoes=&#8221;&#8221;;<br \/>\n20a22<br \/>\n>  cgoes = &#8220;&#8221;;<br \/>\n54a57,60<br \/>\n>   \/\/alert(cgoes);<br \/>\n>   if (cgoes.indexOf(&#8220;;&#8221; + suffix + &#8220;;&#8221;) != -1) {<br \/>\n>    alert(&#8220;Huh?&#8221;);<br \/>\n>   } else {<br \/>\n55a62<br \/>\n>   cgoes = cgoes + &#8220;;&#8221; + suffix + &#8220;;&#8221;;<br \/>\n58c65<br \/>\n<   alert(paris.innerHTML);\n---\n>   \/\/alert(paris.innerHTML);<br \/>\n148a156<br \/>\n>    cgoes = cgoes + &#8220;;&#8221; + nxt.id + &#8220;;&#8221;;<br \/>\n215a224<br \/>\n>    cgoes = cgoes + &#8220;;&#8221; + nxt.id + &#8220;;&#8221;;<br \/>\n218a228<br \/>\n> }<br \/>\nRoberts-MacBook-Pro:htdocs robertmetcalfe$ diff TicTacToe_ConsoleLog.html TicTacToe_NoCheating.html<br \/>\n63,64c63,64<br \/>\n<   var paris=document.getElementById('t' + suffix);\n<   console.log(paris.innerHTML);\n---\n>   \/\/var paris=document.getElementById(&#8216;t&#8217; + suffix);<br \/>\n>   \/\/console.log(paris.innerHTML);<br \/>\nRoberts-MacBook-Pro:htdocs robertmetcalfe$\n<\/p><\/blockquote>\n<p>A couple of good things to note about this Javascript tutorial are:<\/p>\n<ul>\n<li>Ease of use of <a target=_blank title='Javascript global variables' href='http:\/\/snook.ca\/archives\/javascript\/global_variable'>Javascript global variables<\/a><\/li>\n<li>Use of console.log() method in tandem with Firefox&#8217;s <a target=_blank title='console.log() and Firebug' href='https:\/\/getfirebug.com\/logging'>Firebug<\/a> plugin<\/li>\n<\/ul>\n<p>Enjoy the tutorial (or view on <a target=_blank title='Fix Tic Tac Toe Javascript with Firefox Firebug' href='http:\/\/www.youtube.com\/watch?v=RK4PCOqHf-8&#038;feature=youtu.be'>YouTube<\/a>), and see downloadable HTML programming source codes below.<\/p>\n<ul>\n<li><a target=_blank title='TicTacToe_JavascriptDebugTutorial.html' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/TicTacToe_JavascriptDebugTutorial.html_GETME\">TicTacToe_JavascriptDebugTutorial.html<\/a> oversees, in order &#8230;<\/li>\n<li><a target=_blank title='TicTacToe_AsPer_OriginalBug.html' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/TicTacToe_AsPer_OriginalBug.html_GETME\">TicTacToe_AsPer_OriginalBug.html<\/a><\/li>\n<li><a target=_blank title='TicTacToe_IntoInvestigating_OriginalBug.html' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/TicTacToe_IntoInvestigating_OriginalBug.html_GETME\">TicTacToe_IntoInvestigating_OriginalBug.html<\/a><\/li>\n<li><a target=_blank title='TicTacToe_ConsoleLog.html' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/TicTacToe_ConsoleLog.html_GETME\">TicTacToe_ConsoleLog.html<\/a><\/li>\n<li><a target=_blank title='TicTacToe_NoCheating.html' href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/Debug\/TicTacToe_NoCheating.html_GETME\">TicTacToe_NoCheating.html <\/a> or TicTacToe.html<\/li>\n<\/ul>\n<hr \/>\n<p id='fafpt'>Previous relevant <a target=_blank title='Firefox and Favourite Plugins Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=440'>Firefox and Favourite Plugins Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Firefox\/iFrame.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Firefox and Favourite Plugins Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Firefox\/Firefox.jpg\" title=\"Firefox and Favourite Plugins Tutorial\" \/><\/a><p class=\"wp-caption-text\">Firefox and Favourite Plugins Tutorial<\/p><\/div>\n<p><a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Firefox\/iFrame.html'>Tutorial<\/a> &#8230;<\/p>\n<p><strong><\/p>\n<p>Transcript:<\/p>\n<p><\/strong><\/p>\n<p>One of the best tools for Web Development is an HTML element analyzer.<\/p>\n<p>There are a few out there by now, but I really like Firebug from <a target=_blank href='http:\/\/getfirebug.com\/'>http:\/\/getfirebug.com\/<\/a><\/p>\n<p>Both these great tools are plugins for my favourite Web browser Firefox from<br \/>\n    <a target=_blank href='http:\/\/www.mozilla.org\/en-US\/firefox\/new\/'>http:\/\/www.mozilla.org\/en-US\/firefox\/new\/<\/a><\/p>\n<p>Another important tool for Web Development is an ftp application like FireFTP from<br \/>\n    <a target=_blank href='http:\/\/fireftp.net\/'>http:\/\/fireftp.net\/<\/a><\/p>\n<p>So let&#8217;s have a look at Firefox, briefly, and Firebug and FireFTP &#8230;\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d440' onclick='var dv=document.getElementById(\"d440\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Firefox\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d440' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5270' onclick='var dv=document.getElementById(\"d5270\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Firefox\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5270' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s tutorial (live run) shows some debugging techniques for Javascript work that involved the use of Firefox and its wonderful Firebug plugin (instigated via Firefox menu Tools->Web Developer->Firebug->Open Firebug), and builds on your knowledge from previous relevant Firefox and Favourite &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-debug-via-firefox-and-firebug-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[307,438,439,576,652,997,1319],"class_list":["post-5270","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-debugging","tag-firebug","tag-firefox","tag-html","tag-javascript","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5270"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=5270"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5270\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=5270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=5270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=5270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}