100-project-100-days-website/100_projects/54-traffic-lights/main.js

18 lines
382 B
JavaScript
Raw Normal View History

2023-04-16 02:19:49 +03:00
const circles = document.querySelectorAll('.circle')
let activeLight = 0;
setInterval(() => {
changeLight();
}, 1000);
function changeLight() {
circles[activeLight].className = 'circle';
activeLight++;
if(activeLight > 2) {
activeLight = 0;
}
const currentLight = circles[activeLight]
currentLight.classList.add(currentLight.getAttribute('color'));
}