{"id":20526,"date":"2016-03-07T03:01:52","date_gmt":"2016-03-06T17:01:52","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=20526"},"modified":"2016-03-06T19:02:25","modified_gmt":"2016-03-06T09:02:25","slug":"javascript-associative-array-quiz-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-associative-array-quiz-tutorial\/","title":{"rendered":"Javascript Associative Array Quiz Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Javascript Associative Array Quiz Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/treechalkboard.jpg\" title=\"Javascript Associative Array Quiz Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Javascript Associative Array Quiz Tutorial<\/p><\/div>\n<p>We consolidate yesterday&#8217;s <a title='Javascript Associative Array Primer Tutorial' href='#jaapt'>Javascript Associative Array Primer Tutorial<\/a> with today&#8217;s HTML and Javascript web application where we use Javascript <a target=_blank title='Javascript object information from w3schools' href='http:\/\/www.w3schools.com\/js\/js_objects.asp'>objects<\/a> as a way to have <a target=_blank title='Associative array information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Associative_array'><i>associative array<\/i><\/a> thoughts permeate your client side web application logic.<\/p>\n<p>Today we &#8230;<\/p>\n<ol>\n<li>add a &#8220;Previous&#8221; way to navigate along the Associative Array data structure &#8230; in addition to yesterday&#8217;s &#8220;Next&#8221; way (that <i>linked lists<\/i> are very fond of)<\/li>\n<li>add background imagery for a tree<\/li>\n<li>change border arrangements for &#8220;root&#8221; and &#8220;canopy&#8221; of tree<\/li>\n<li>allow display modes [Tree Creeper], Tree, Creeper, Weeping Tree &#8230; with different looks via CSS styling via HTML class definitions established via URL mechanisms teamed with a <i>document.write<\/i> &#8220;delayed write out of HTML&#8221; Javascript technique<\/li>\n<li>allow the concept of a Tree <i>name<\/i> via user specific arrangements involving a colon (:) when defining the (tree) root value<\/li>\n<li>establish a quiz functionality to the web application &#8230; optional, of course<\/li>\n<\/ol>\n<p>Step 4 above needed us to explore CSS <a target=_blank title='CSS transform and rotaton information from w3schools' href='http:\/\/www.w3schools.com\/css\/css3_2dtransforms.asp'><i>rotation<\/i><\/a> techniques on the (new) HTML div element (now) encasing the HTML table we talked about with yesterday&#8217;s tutorial.<\/p>\n<p>Today&#8217;s HTML and Javascript programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html-GETME\" title='tree_chalkboard.html'>tree_chalkboard.html<\/a> has this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html\" title='Click picture'>live run<\/a> link, and this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html-GETME\" title='tree_chalkboard.html'>link<\/a> shows the changes made since yesterday.  Again, we&#8217;d like to thank <a target=_blank title='Useful link' href='http:\/\/www.quirksmode.org\/js\/associative.html'>this link<\/a> for its great advice regarding Javascript objects and their associative array &#8220;look&#8221; possibilities.<\/p>\n<hr>\n<p id='jaapt'>Previous relevant <a target=_blank title='Javascript Associative Array Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-associative-array-primer-tutorial\/'>Javascript Associative Array Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Javascript Associative Array Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.jpg\" title=\"Javascript Associative Array Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Javascript Associative Array Primer Tutorial<\/p><\/div>\n<p>Today&#8217;s HTML and Javascript web application uses Javascript <a target=_blank title='Javascript object information from w3schools' href='http:\/\/www.w3schools.com\/js\/js_objects.asp'>objects<\/a> as a way to have <a target=_blank title='Associative array information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Associative_array'><i>associative array<\/i><\/a> thoughts permeate your client side web application logic.<\/p>\n<p>The idea of an <i>associative array<\/i> has a lot of appeal, in the same way we humans, hopefully, prefer to call each other by our <i>name<\/i> rather than our <i>number<\/i>.  Don&#8217;t feel sorry for the trouble you&#8217;re causing the computer thinking in terms of arrays with names rather than numbers &#8230; <font size=1>they&#8217;ll get over it<\/font> &#8230; but there is a small consideration with massive amounts of data that the computer will do that massive amount of calculation faster using a numerical index on a huge array, rather than an associative indexing system.<\/p>\n<p>Today we have the user create up to 5 tree hierarchies, initialised via<\/p>\n<p><code>var Questions = [new Object(), new Object(), new Object(), new Object(), new Object()];<\/code><\/p>\n<p>this approach that ends up a lot like a <a target=_blank title='Linked list information from Wikipedia ... thanks' href='https:\/\/en.wikipedia.org\/wiki\/Linked_list'>linked list<\/a>.  We provide you with a guaranteed reference to the root element of <i>Tree x<\/i> as <i>Questions[x].Text<\/i> and the value contained in Questions[x].Text fed through a homespun Javascript function enumis() gets you going so that &#8230;<\/p>\n<p><code>var nextis = eval(\"Questions[x].\" + enumis(Questions[x].Text) + \"Next\")<\/code><\/p>\n<p> &#8230; would get you to the next place on the tree &#8230; and can you guess you could then go &#8230;<\/p>\n<p><code>nextis = eval(\"Questions[x].\" + enumis(nextis) + \"Next\")<\/code><\/p>\n<p> &#8230; to keep going up the tree, perhaps all the way to our green bordered &#8220;canopy&#8221;.  As you can see, to be a friend of Javascript <a target=_blank title='Javascript eval() method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp'>eval()<\/a> is a very wise move for a huge number and variety of client web application issues and solutions.<\/p>\n<p>HTML display wise what we do is to start with an HTML <i>table<\/i> and <i>tbody<\/i> and 5 <i>tr<\/i> row elements, initially with just 1 <i>td<\/i> cell (per row) containing the HTML <i>input<\/i> type=text where the user enters their data.  At the HTML <i>body<\/i> onload event we snapshot this scenario exactly like that, and add into the end of the 1 <i>td<\/i> cell an HTML <i>div<\/i> element given an ID (for Javascript DOM purposes).  As we build any one tree to be &#8220;taller&#8221; (in our case, we have right to left &#8220;climbers&#8221;) that aforesaid mentioned HTML <i>div<\/i> has its <i>innerHTML<\/i> property populated with the next HTML <i>input<\/i> type=text (derivable from that snapshotted first HTML <i>input<\/i> type=text element of the row) and HTML <i>div<\/i> element &#8220;child&#8221; set (of new HTML elements).  So you end up with the 1 cell per row, and things are helped to stay &#8220;connected&#8221; by the CSS <i><a target=_blank title='CSS float property information from w3schools' href='http:\/\/www.w3schools.com\/css\/css_float.asp'>float<\/a>:left<\/i> property applied to the HTML <i>div<\/i> elements.<\/p>\n<p>Today&#8217;s HTML and Javascript programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html_GETME\" title='tree_chalkboard.html'>tree_chalkboard.html<\/a> has this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/tree_chalkboard.html\" title='Click picture'>live run<\/a> link.  We&#8217;d like to thank <a target=_blank title='Useful link' href='http:\/\/www.quirksmode.org\/js\/associative.html'>this link<\/a> for its great advice regarding Javascript objects and their associative array &#8220;look&#8221; possibilities.<\/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='#d20505' onclick='var dv=document.getElementById(\"d20505\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/associative-array\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20505' 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='#d20526' onclick='var dv=document.getElementById(\"d20526\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/rotation\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d20526' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We consolidate yesterday&#8217;s Javascript Associative Array Primer Tutorial with today&#8217;s HTML and Javascript web application where we use Javascript objects as a way to have associative array thoughts permeate your client side web application logic. Today we &#8230; add a &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-associative-array-quiz-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,28,37],"tags":[1819,184,281,354,399,576,652,703,849,875,997,1072,1319],"class_list":["post-20526","post","type-post","status-publish","format-standard","hentry","category-elearning","category-oop","category-tutorials","tag-associative-array","tag-canvas","tag-css","tag-dom","tag-eval","tag-html","tag-javascript","tag-linked-list","tag-object","tag-oop","tag-programming","tag-rotation","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20526"}],"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=20526"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20526\/revisions"}],"predecessor-version":[{"id":20532,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/20526\/revisions\/20532"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=20526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=20526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=20526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}