The biggest challenge with this one was figuring out how to do multiple calculations, and also doing multiplicative calculations before handling additive ones. The way I handled this was define an array for all calculations, and once the user clicks the equal button (or hits Enter), the array is iterated once for handling all multiplicative calculations, reducing the array to additive calculations, and then the array is iterated once more for handling those in turn.
For example, let’s assume the user types in 1+2*2/4, then the array would look like this:
["1", "+", "2", "*", "2", "/", "4"]. On first iteration, the array is reduced to the following:
["1", "+", "1"]. On second iteration, 1+1 is evaluated and the result 2 is returned.
Other challenges were preventing multiple consequent operations to be added to the array (e.g.
I know the project could probably be done in a better way and more efficiently, but I tried my best to do it the best way possible with my current skillset. Also, as a side note, considering this is a speedrun, I haven’t spent much time making it look closer to a real calculator, but I definitely plan to do so when I build the project as not part of a speedrun.