+ 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

20th Mar 2018, 3:59 PM
Type
Type - avatar
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 :)
20th Mar 2018, 5:01 PM
Just A Rather Ridiculously Long Username
+ 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.
20th Mar 2018, 8:38 PM
Just A Rather Ridiculously Long Username
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!
20th Mar 2018, 5:14 PM
Type
Type - avatar
0
I like the use of modulus too btw
20th Mar 2018, 5:34 PM
Type
Type - avatar
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
20th Mar 2018, 5:52 PM
Type
Type - avatar
0
Thanks once again I totally missed that.
21st Mar 2018, 3:35 AM
Type
Type - avatar