Jump to content

[SOLVED] javascipt color change effect


alex242
 Share

Recommended Posts

The problem may not be so obvious, but it still should not be happening. The rate of the 'setTimout' is set so slow so you can see the problem more clearly. The problem is that sometimes the color repeats itself, causing a visual 'hang' in the color change of the text. I have written some code that should be working to stop this issue, but it does not appear to be working. What is wrong?

<html><head><script type='text/javascript'>var colors = new Array('black','red','green','blue','brown','chocolate','purple','gray','olive');function hellow(y){x = Math.floor(Math.random()*10);while(x == y){x = Math.floor(Math.random()*10);}document.getElementById('hello').style.color = colors[x]var t = setTimeout('hellow(x)',500);}</script></head><body onload='hellow(1)'><h1 id='hello'>HELLO WORLD!</h1></body></html>

Edited by alex242
Link to comment
Share on other sites

uhh... Sorry everybody... I'm an Idiot.It was working just fine. I just didn't have a ninth color name listed, so it appeared to hang when the random number x equaled 9.Sorry again...this thread should be closed so It doesn't waste anyone else's time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...