Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
that sounds like a non-updated 'pressed' at time of calling countBombs... you could try to introduce some delay before calling click handler: setTimeout(() => c.click(),100); you may try different delays (minimal delay is around 4ms) however, this will introduce some display delay, so you'll need to not give too much delay, or store cell pressed state as an external array rather than on element classList ;)
14th Mar 2021, 2:13 PM
visph
visph - avatar
+ 2
I cannot reproduce your bug... and I do not see in your code what could produce a call stack overflow, as you are checking if 'pressed' was set to cell before calling its click handler (and set is done before calling countBombs in cellClickHandler)...
14th Mar 2021, 1:58 PM
visph
visph - avatar
+ 1
no, I'm quite surprising that you cannot do it without a timeout... but as already said, using timeout is a quick fix, and you'll be advised to store pressed states outside of elements to prevent this kind of issue ;)
14th Mar 2021, 2:35 PM
visph
visph - avatar
+ 1
anyway, you could try to store such state as 'dataset' on element (maybe it will be updated as soon as assigned), as dataset are used to store user defined attributes on elements (while class may be refreshed only on reflow/repaint)...
14th Mar 2021, 2:49 PM
visph
visph - avatar