Created
March 15, 2016 23:37
-
-
Save c01nd01r/1358bc8d977a801518f3 to your computer and use it in GitHub Desktop.
Светофор / BasicQual#3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trafficLight() { | |
var red = document.querySelector(".red"); | |
var yellow = document.querySelector(".yellow"); | |
var green = document.querySelector(".green"); | |
var timer = 0; | |
function engine() { | |
switch (timer) { | |
case 0: | |
red.classList.add("active"); | |
yellow.classList.remove("active"); | |
yellow.classList.add("redText"); | |
break; | |
case 19: | |
yellow.classList.remove("redText"); | |
yellow.classList.add("active"); | |
break; | |
case 22: | |
red.classList.remove("active"); | |
yellow.classList.remove("active"); | |
yellow.classList.add("greenText"); | |
green.classList.add("active"); | |
break; | |
case 44: | |
yellow.classList.add("active"); | |
yellow.classList.remove("greenText"); | |
green.classList.remove("active"); | |
break; | |
case 47: | |
trafficLight(); | |
break; | |
} | |
if (timer < 45) { | |
yellow.innerHTML = (timer < 22) ? 22 - timer : 44 - timer; | |
} | |
timer++; | |
} | |
setInterval(engine, 1000); | |
} | |
trafficLight(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment