+ 1

Javascript Maximum call stack exceeded

Help, I received error: UncaughtError: Maximum call stack exceeded What should I do to fix this error, as you can see, I'm trying to make metronome using JS. The problem is, I received that error. I just would like to chage the speed of animation. https://code.sololearn.com/Wzo0y9Aur468/?ref=app

15th Apr 2022, 12:05 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar
9 odpowiedzi
+ 2
// Don't forget it :) // [0] to get the first element return document.getElementsByClassName('barPercent')[0].style.animationDuration = metronomeBarSpeed;
15th Apr 2022, 3:23 AM
SoloProg
SoloProg - avatar
+ 2
Document.getElementsByClassName() The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class name(s). https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName Have a read
15th Apr 2022, 2:33 AM
SoloProg
SoloProg - avatar
+ 2
Get the first element with a class of 'barPercent', or undefined if there is no matching element: document.getElementsByClassName('barPercent')[0]
15th Apr 2022, 2:36 AM
SoloProg
SoloProg - avatar
+ 1
not sure if i got this right, but i know this happens in recursive methods
15th Apr 2022, 12:29 AM
Keokix_
Keokix_ - avatar
+ 1
// try this .. cssBarSpeed function document.getElementsByClassName('barPercent')[0].style.animationDuration = metronome.speedOfBeat();
15th Apr 2022, 2:19 AM
SoloProg
SoloProg - avatar
+ 1
SoloProg thanks for trying, there's no error if I put that, but the animationDuration didn't change. By the way, please enlighten me What is [0] in [0].style? What can [0] do?
15th Apr 2022, 2:28 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar
+ 1
SoloProg thanks I understand now, I just updated the code, please check it again. What I want is, for the animation Speed, or the duration of the animation change. How can I do it? The error now changed
15th Apr 2022, 2:50 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar
+ 1
SoloProg thanks so much, you just save me from this problem, it's messing with my brain for a long time XD. Many thanks 🥰
15th Apr 2022, 3:29 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar
0
Keokix_ yeah I just also learned that just now, thanks for saying that, so how can I solve this problem. I tried putting return statement in every method, but still not working
15th Apr 2022, 12:33 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar