0
Why does this happen?
In the function start(), if i put "let" or "var" to the variable the interval doesn't stop, but if I don't put anything it works (Sorry for my english) https://code.sololearn.com/W4SqrXoBLqGm/?ref=app
5 Answers
+ 4
`var` defines something at function scope when placed inside a function. `var` defines something at global scope when it is placed outside a function.
`let` is even more scope aware, in that it can define something at block scope rather than function scope.
So, if you use `let` or `var` it means you are defining another <str> inside function start(), rather than using the <str> defined outside function start(). And that <str> variable is only recognized inside function start().
+ 1
Try putting in a boolean variable where the counting function checks if it's true before adding.
https://code.sololearn.com/WHMsf5zNPIoa/?ref=app
+ 1
Intervals are buggy. I'm not sure what's causing yours to wig out, but I know that it's pretty normal. Whenever I use intervals, I'll generally make one interval that's always running on page load as a sort of Update function, and then just use booleans to do stuff in it.
+ 1
Thanks!
0
Sorry, I wanted to know why this happens