+ 1
Problem with my JS code
The first cycle works fine but on the second I think the setInterval function gets overloaded or something I would appreciate if anyone knows what actually goes wrong. https://code.sololearn.com/WQ0X4qjn2XV2/?ref=app
6 Answers
+ 1
Don't know what exactly was going wrong, but here are some problems in your code:
âąYou shouldn't use multiple setInterval() functions unless you know exactly what you're doing; a better alternative is to put all your functions into one function and call it through setInterval(). This way you can also manage the order in which they are called.
âąYour color changing function was all over the place, you could have used something much simpler
I just changed up those two things and that seemed to have fixed it.
https://code.sololearn.com/WYoiKcQtLVNm/#js
Let me know if I can clear anything else up :)
+ 1
No problem!
And yes, you can easily change the rgb values as much as you want. The mistake here is that you are setting all three values to zero every time you are calling the function. One way to do it would be:
https://code.sololearn.com/WYoiKcQtLVNm/#js
This is probably a stupid way to do it but its what i could come up with. You can look up better ways to change the color.
0
Thanks a lot. I was going to make a function for the color change part but didnât know how to do it. Your edits are very clear and understandable thanks again!
0
I like the use of modulus too btw
0
I have 1 more question if you donât mind, how could I increase the rgb values by however much I wanted to instead of the math.random? I tried here https://code.sololearn.com/Wpa2TLqZ9BOJ/?ref=app
0
Thanks once again I totally missed that.