0

Whats wrong in this code? (JS)

Whats wrong there? I can't find whats wrong. https://code.sololearn.com/WV89yXsY98en/ JS, line: 5 (Text is in german)

13th Feb 2019, 8:13 PM
JanJakCode
JanJakCode - avatar
4 Answers
+ 2
The problem is than the i var in time function is always 0 at start of any time() call then though you inctement it (its temporary and not global). Inside time() uoua will get a reference to button and if i<1 you remove it BUT its always the case then you will access to a null refetence to button (returned by getElementById) and, without checks, you try to access to a field of null object raising an exception
13th Feb 2019, 8:20 PM
KrOW
KrOW - avatar
+ 2
you have to declare let i = 0; outside the time function. otherwise it will always be 0.
13th Feb 2019, 8:21 PM
Esteban Juarez Rodriguez
Esteban Juarez Rodriguez - avatar
+ 2
👍👍👍
13th Feb 2019, 8:36 PM
KrOW
KrOW - avatar
+ 1
Its working now. Thank you!
13th Feb 2019, 8:26 PM
JanJakCode
JanJakCode - avatar