Digital game algorithm

I am currently doing some research into creating a new math game for elementary school children, where divs from 0-9 appear randomly in a container.

The question is asked at the beginning. Something like a multiple of 20. Then the user will need to click on the correct ones, and then they will be counted at the end, and an assessment will be given.

So, at the moment I have a basic structure, divs appear, and you click on them, and this adds the correct answer, which means that at this moment there is no wrong answer.

I want to know what is the best way to determine the correct and incorrect answers. Is there an algorithm that I can use that will determine if the answers are right or wrong, and how would I link it to a div?

<div id="container"> <div id="char1" class="character right1" vaule="1"></div> <div id="char2" class="character right2" vaule="2"></div> <div id="char3" class="character right3" vaule="3"></div> <div id="char4" class="character right4" vaule="4"></div> <div id="char5" class="character right5" vaule="5"></div> <div id="char6" class="character right6" vaule="6"></div> <div id="char7" class="character right7" vaule="7"></div> <div id="char8" class="character right8" vaule="8"></div> <div id="char9" class="character right9" vaule="9"></div> <div id="char9" class="character right0" vaule="0"></div> </div> 

incorrect answers will be assigned the class ".wrong", which was added to ".right"

Fiddle: http://jsfiddle.net/SKB3Q/10/

+4
source share
3 answers

The first thing you need to do is come up with the question of what right or wrong to make sense.

For example: "Click all numbers that are greater than 20"

The second thing you need to do is express this question as a logical expression that evaluates to true or false.

 (selection>20) 

Then evaluate this expression for each choice to determine if it is right or wrong.

Here is an example of what I mean. Before starting the game, the script adds a corresponding class to each element. Question: "Select all numbers greater than 5"

+1
source

Actually, I made a balloon game that resembles this ...

As you did the design and animation, 70% of the work works fine: D, small modifications in the logic will complete the work ......

My solution would be: if the div in the container is static, and you gave an identifier for them, then Step1: check what division the button is pressed for, and then what value is assigned to it

Step 2: check the boolean expression (as per your requirement) here and increment the correct flag or invalid flag declared globally according to your boolean expression

Sample code that can help you

 for(var i=0;i<8;i++) { $("#char"+i).click(function(){ //boolean expression comes here //increase the correct count or the incorrect count you want to do it }) } 
+1
source

I did not see exactly your code, if char1, char2, char3, .... are randomly generated divs and 1,2,3, ..... are the values ​​associated with this, then try this code and let me know

 <script type="text/javascript"> for (var i = 0; i < 8; i++) { $("#char" + i).click(function () { var val = $("#char" + i).val(); // so by this you will get the which one is clicked if (val % 15 == 0) hit++; else miss++; $("#hit").html("correct: " + hit); $("#miss").html("Incorrect: " + miss); }) } </script> 

therefore, when a div is ever activated and the user clicks on it, this function is called and checks the Boolean expression and, accordingly, increases hit flags or skips.

Note. Assuming Char1, char2, ... are randomly resolving divs unless you write a condition for the corresponding randomly generated div, which will work fine

"you can check for any multiple values ​​by simply changing the boolean expression that I specified above (val% 15 == 0)"

0
source

Source: https://habr.com/ru/post/1441248/


All Articles