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

18th Jan 2022, 10:08 PM
Javier Rodas
Javier Rodas - avatar
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().
18th Jan 2022, 10:43 PM
Ipang
+ 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
18th Jan 2022, 10:11 PM
Brian Dean Ullery
Brian Dean Ullery - avatar
+ 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.
18th Jan 2022, 10:25 PM
Brian Dean Ullery
Brian Dean Ullery - avatar
+ 1
Thanks!
19th Jan 2022, 1:24 AM
Javier Rodas
Javier Rodas - avatar
0
Sorry, I wanted to know why this happens
18th Jan 2022, 10:20 PM
Javier Rodas
Javier Rodas - avatar