Skip to content

Instantly share code, notes, and snippets.

@c01nd01r
Created March 15, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c01nd01r/1358bc8d977a801518f3 to your computer and use it in GitHub Desktop.
Save c01nd01r/1358bc8d977a801518f3 to your computer and use it in GitHub Desktop.
Светофор / BasicQual#3
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