-4

I found this answer with a simple JavaScript counter. How can I change the color of the counter, for e.g.:

  • When it is above 10 seconds, its becomes red
  • When it is above 20 seconds, it becomes orange.
  • When it is above 30 seconds, it becomes blue.
Community
  • 1
  • 1
Village
  • 22,513
  • 46
  • 122
  • 163

1 Answers1

1

you could do something like this.

if( timerCount > 10 && timerCount < 20 )
    timerDiv.style.color = 'Your color';
else if( timerCount > 20 && timerCount < 30 )
    timerDiv.style.color = 'Your color';
else
    timerDiv.style.color = 'Your color';

// timerCount is the variable being incremented // timerDiv is the variable that is going to be the div being incremented.

Edit suggested by @user3980820

Hawk
  • 788
  • 1
  • 6
  • 18
  • 1
    maybe you should edit your code because when it's above 20 it will only go on the first condition. `if( totalSeconds > 10 && totalSeconds <20 )` and so I hope this will improve your code. – Abdessabour Mtk Sep 15 '14 at 11:58
  • and also you should change the `elseif` statement to `else if( timercount > 20 && timercount < 30) – Abdessabour Mtk Sep 15 '14 at 13:12