{"id":3349,"date":"2013-06-18T22:33:20","date_gmt":"2013-06-19T03:33:20","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=3349"},"modified":"2013-06-18T22:39:15","modified_gmt":"2013-06-19T03:39:15","slug":"javascript-cant-be-in-two-places-at-the-same-time-a-rant-on-math-games","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/javascript-cant-be-in-two-places-at-the-same-time-a-rant-on-math-games\/","title":{"rendered":"Javascript can&#8217;t be in two places at the same time &#038; a rant on math games"},"content":{"rendered":"<p>Spirit Lake: The Game is mostly an adventure game that teaches math. However, it has lots of Easter eggs, side quests and spin-offs added because hey, these are kids and sometimes they like to do something different and some of them have the attention span of an ant.<\/p>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/11\/splash-screenSm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2760\" alt=\"Splash Screen\" src=\"http:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/11\/splash-screenSm-300x214.jpg\" width=\"300\" height=\"214\" srcset=\"https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/11\/splash-screenSm-300x214.jpg 300w, https:\/\/www.thejuliagroup.com\/blog\/wp-content\/uploads\/2012\/11\/splash-screenSm.jpg 504w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Our idea is to make the game fun, even when you get the answers wrong, you get sent to do something else that&#8217;s fun. I saw a Flash game that used refrigerator magnets for division problems which seemed pretty fun, but we are avoiding Flash since we want our game to be easily portable to iPads from the current version that runs on Mac OS and Windows. So &#8230; <a href=\"http:\/\/www.7generationgames.com\/magnets\/magnets.html\">I spent today writing a refrigerator magnet division application. You can see it here.<\/a> It still could use a bit of tweaking &#8211; I \u00a0need to add the refrigerator background and I think I&#8217;ll change the pictures of magnets I have to some that are more cute and fun.<\/p>\n<p>Being our child, The Spoiled One did not even ask why The Invisible Developer was in the kitchen taking pictures of the refrigerator.<\/p>\n<p>Here is the problem I ran into &#8230;. it was working fine EXCEPT if I had a problem like 36 \u00f7 6 in which case the second value was blank and all I got was<\/p>\n<p>36 \u00f7<\/p>\n<p>It was as if the image (remember, each number is a picture of a refrigerator magnet), could only be used once. Well, of course, that WAS the problem.<\/p>\n<p>From the enormously helpful <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Node.appendChild\">Mozilla Developer Network<\/a><\/p>\n<blockquote><p><strong>If\u00a0<code>child<\/code>\u00a0is a reference to an existing node in the document,\u00a0<code>appendChild<\/code>\u00a0moves it from its current position to the new position (i.e. there is no requirement to remove the node from its parent node before appending it to some other node).<\/strong><\/p>\n<p><strong>This also means that a node can&#8217;t be in two points of the document simultaneously. So if the node already has a parent, it is first removed,\u00a0<em>then<\/em>\u00a0appended at the new position.<\/strong><\/p><\/blockquote>\n<p>I was doing exactly \u00a0that, the offending statement is shown with *** below<\/p>\n<p><code>function getProb()<br \/>\n{<\/code><\/p>\n<p><code>var choose2=randnum(1,9);<\/code><br \/>\n<code>var temp=randnum(1,9);<\/code><br \/>\n<code>var choose1 = choose2 *temp ;<\/code><br \/>\n<code>rightanswer=choose1 \/ choose2;<\/code><br \/>\n<code>w = choose1 + \"\" ; x = w.substring(0,1) ;<br \/>\n** document.getElementById(\"pic\").appendChild(imgArray[(choose2)]);<br \/>\ndocument.getElementById(\"tot\").appendChild(imgArray[(x)]);<br \/>\nif (w.substring(1,2) )<\/code><br \/>\n<code><br \/>\n{<br \/>\ny = w.substring(1,2) ;<br \/>\ndocument.getElementById(\"tot2\").appendChild(imgArray[(y)]);<br \/>\n}<br \/>\n}<\/code><\/p>\n<p>What this snippet does is generate a random number between 1 and 9, then generate a second random number. \u00a0The two random numbers are multiplied to give me a product of two numbers between 1 and 9 because the game progresses gradually in difficulty from early levels that assume children have not yet mastered division with remainders, and this little applet goes into an early level. So, the number which we use as our divisor should be divisible without a remainder.<\/p>\n<p>The divisor (which, of course goes first in a division problem) divided by the second number shown on the page (choose2, our dividend) gives us the right answer.<\/p>\n<p>Earlier in the program (not shown) I had created an array which was like this<br \/>\n<code><br \/>\nvar imgArray = new Array() ;<br \/>\nimgArray[0] = new Image() ;<br \/>\nimgArray[0].src = \"zero.png\" ;<br \/>\nimgArray[1] = new Image() ;<br \/>\nimgArray[1].src = \"one.png\" ;<br \/>\n<\/code><br \/>\nThe answer is going to be between 1 and 9, so I can take whatever it is, find the same number in the array and put that image into the cell for the dividend.<\/p>\n<p>I need to break the number to be divided down into digits because, remember, these are refrigerator magnets and numbers between 1 and 9, so each digit is a separate image. I did it by making a string variable by adding &#8220;&#8221; to choose1. I then took the first digit and put that image into a table cell. If there was a second digit, I took the \u00a0image in the array corresponding to that and put that into another table cell.<\/p>\n<p>BUT &#8230;. what happened was when a number was used twice, like in the example of 36 divided by 6, when I appended the 6 to the divisor, it was removed from the dividend cell.<\/p>\n<p>How to solve this? Well, one way is to create another array of images, which I did, both because it was a super simple solution and I immediately thought of several other reasons off the top of my head why that might be useful. I can certainly envision using this code again in the game, for example, to emphasize which is the divisor and which is the dividend. There are lots of points where students confuse the two, or fail to understand that you cannot switch them around and still get the same answer, like you do with multiplication. In fact, I&#8217;m already thinking about having the numbers for the dividend being red or flashing (probably not) or from a different set of magnets.<\/p>\n<p>So, there you have a nifty little reminder about how appendChild works and a super-simple way to fix a possible problem.<\/p>\n<p>There is also another point in here I&#8217;d like to make. Last night, I attended a meet-up on gaming where some people were\u00a0<em>positive\u00a0<\/em>that they did not need to know anything about math education to write a math game because, <em>&#8220;Hey, everybody knows K-12 math and the teachers know how to teach it.&#8221;<\/em><\/p>\n<p>Yes, most teachers do know exactly what their students should be learning, but do YOU? Because if you have a game that is assuming students can divide numbers that have remainders and the students are not at that point yet, they will be frustrated. It really isn&#8217;t the teacher&#8217;s responsibility to insure that your game that you say is at fourth grade level really is. Even if it is, at what point in fourth grade? What exactly does it teach? When should he or she be introducing it to the students? At the end of the school year? At the beginning? Do you know what a divisor or dividend is and that students often mix them up? What area of mathematics do most students have problems with in fourth and fifth grade? What should your game emphasize?<\/p>\n<p>I think the fact that many math educational game designers don&#8217;t give much attention at all to math is why most math educational games suck at being educational, no matter how cool they may be as games.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spirit Lake: The Game is mostly an adventure game that teaches math. However, it has lots of Easter eggs, side quests and spin-offs added because hey, these are kids and sometimes they like to do something different and some of them have the attention span of an ant. Our idea is to make the game&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,9],"tags":[],"class_list":["post-3349","post","type-post","status-publish","format-standard","hentry","category-computer-games","category-software"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=3349"}],"version-history":[{"count":5,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3349\/revisions"}],"predecessor-version":[{"id":3354,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/3349\/revisions\/3354"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=3349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=3349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=3349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}