{"id":604,"date":"2011-05-03T22:28:10","date_gmt":"2011-05-04T04:28:10","guid":{"rendered":"http:\/\/bateru.com\/news\/?p=604"},"modified":"2011-05-05T23:01:13","modified_gmt":"2011-05-06T05:01:13","slug":"jquizme-example-simple-math-quiz","status":"publish","type":"post","link":"https:\/\/bateru.com\/news\/2011\/05\/jquizme-example-simple-math-quiz\/","title":{"rendered":"jQuizMe Example: Simple Math Quiz"},"content":{"rendered":"<p>Here&#8217;s an example of jQuizMe.<br \/>\n<b>Goal:<\/b> Make a quiz for Addition, Subtraction and Multiplication for two digit numbers.<\/p>\n<p><b>Steps:<\/b><\/p>\n<ol>\n<li>Make a random number generator.<\/li>\n<li>Make a function to form a question and answers.<\/li>\n<li>Form the quiz.<\/li>\n<li>Call jQuizMe<\/li>\n<\/ol>\n<p><b>Step 1:<\/b><br \/>\nI wrote a random number generator in javascript <a href=\"http:\/\/bateru.com\/news\/2011\/03\/code-of-the-day-javascript-random-number-generator\/\">here<\/a>. <\/p>\n<pre lang='javascript' line=\"1\">\r\nvar getRandomNum = function( i, decLen ){\r\n\tvar powOf10s = Math.pow( 10, decLen || 0 );\r\n\treturn i ?  Math.floor( powOf10s * Math.random() * i ) \/ powOf10s : Math.random();\r\n};\r\n<\/pre>\n<p>Or.. you could just use Math.floor( Math.random() * number ).<\/p>\n<p><b>Step 2 &#038; 3:<\/b> (Due to time constraints I combined step 2 and 3.)<\/p>\n<pre lang='javascript' line=\"1\">\r\nvar link = \"http:\/\/bateru.com\/news\/2011\/04\/learn-sig-figs-in-no-time\/\";\r\nvar ops = operations = [ \" + \", \" - \", \" * \", \" \/ \" ];\r\nvar precision = 2;\r\n\r\nvar arrOfRandomNum = function( arrLength, max, decLen ){\r\n\tif( arrLength < 0 ){ return false; }\r\n\tvar arr = [], i = arrLength;\r\n\twhile( i-- ){\r\n\t\tarr[ i ] = getRandomNum( max, decLen );\r\n\t}\r\n\treturn arr;\r\n};\r\nvar makeQuiz = function(){\r\n\tvar quiz = { \"fill\":[] };\r\n\tvar question = '', nums = [];\r\n\tvar i = questionLength = 10;\r\n\twhile( i-- ){\r\n\t\tnums = arrOfRandomNum( 2, 19 );\r\n\t\tquestion = nums.join( ops[ getRandomNum( ops.length ) ] );\r\n\t\tquiz.fill.push({\r\n\t\t\tques: question,\r\n\t\t\tans: eval( question ).toPrecision(precision)\r\n\t\t});\r\n\t}\r\n\treturn quiz;\r\n}\r\n<\/pre>\n<p><b>Step 4:<\/b><\/p>\n<pre lang='javascript' line=\"1\">\r\n$( \"#quiz\" ).jQuizMe( makeQuiz(), {\r\n\tintro: ops.join(',') + \" quiz.<br>Note: Your answer must have \" + precision + \" <a href='\"+link+\"'>sig figs<\/a>.\"\r\n});\r\n<\/pre>\n<p>Here's the working demo.<br \/>\n<iframe src=\"http:\/\/bateru.com\/projects\/jquizme\/simpleMathQuiz.html\" style=\"width:30em;height:30em;\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s an example of jQuizMe. Goal: Make a quiz for Addition, Subtraction and Multiplication for two digit numbers. Steps: Make a random number generator. Make a function to form a question and answers. Form the quiz. Call jQuizMe Step 1: I wrote a random number generator in javascript here. var getRandomNum = function( i, decLen &hellip; <a href=\"https:\/\/bateru.com\/news\/2011\/05\/jquizme-example-simple-math-quiz\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">jQuizMe Example: Simple Math Quiz<\/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":[11,23,62,12,10],"tags":[71,6,166],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-frontend-tech","category-math","category-questions-and-answers","category-science","category-tutorials","tag-how-to-use","tag-jquizme","tag-math"],"_links":{"self":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/comments?post=604"}],"version-history":[{"count":12,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/604\/revisions\/630"}],"wp:attachment":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/media?parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/categories?post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/tags?post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}