Hi, I’m trying to create something similar to this web game called Mathler, https://www.mathler.com/
and here is mine on codepen.
Basically, the game is similar to Wordle, but it’s in math. The game gives you a random number and you have to figure out the correct calculation that equals to the random number. And the calculation has to be 6 inputs long, including numbers and symbols.
My approach to this project is to generate a random number and generate calculations with conditions (not completely finished), and once the calculations were generated, I want to calculate the calculations to make sure they equal to the number, if one calculation is matched, then we have the answer users need to figure out. However, I’m stuck on this approach, I will explain this later on.
There is an alternative solution, which is to generate random calculations with the correct conditions, once one calculation is generated and it’s valid, the code can stop. Then we calculate the calculation to get the output, and the output would be the “random” number given to users. I personally think this is a better approach but my friend said this method is not efficient.
Both solutions require the code to actually calculate, which is another problem that I don’t know how to solve, I thought about saving the numbers into an empty array, for example, calculation = 1+45-4, perhaps I could save the numbers into an array, so something like [1, 45, 4], then program the code to recognize the plus and minus symbols, and using switch and case to calculate the output of first value from the array and second value from the array, and so on. But how can I program the code to read double digit numbers as in forty-five rather than four-five and group the two together as one value?
I want to know which approach is more appropriate in this case, or if there’s another easier and more efficient way to do this? I do think generate all those calculations will take up a lot of time but this is the best I could do right now. Any help would be greatly appreciated!