After collecting 11th food, game crashes/freezes don't know what happens, but you are forced to restart whole app, cause non other codes runs after.
I was trying to find place where it may happen for arround 4h with no luck.
Interesting question, I can experience what you mean by "you are forced to restart whole app".
The problem is caused by an infinite loop.
Try to add a counting variable in before your while loops and add an exit condition based on this counting variable for every while loop you implement.
Try also to add a let in each for loop.
For example, for(i2=0;... and for(i=0;...
these will cause the i and i2 be a global scope variable and other function may change its value at the same time, making it impossible to quit the for loop.
for(let i2 = 0; i2 <....
and for(let i = 0; i <...
OMG, thank you very much :)))
Works like a charm.
The main problem was, that I left one for loop, which caused infinite loop. I found it only cause of i variables that you mentioned :)
= = = = =
P.s. I've put let before all variables in for loops.
Thanks again, it was a huge help :)
You are welcome, Dower.
Let me explain a little bit about what happens when we don't add var or let keyword, and also among var and let which one is preferred.
When you use a variable without declaring it, it becomes a property of window object, which is also known as global variable. (See Fact #063)
var is a pre-ES6 keyword for declaring functional scope variable, and will be hoisted; let is a ES6 keyword for declaring block-scope variable, and will not be hoisted. let is safer and preferred. (See Fact #023)