100-project-100-days-website/100_projects/54-traffic-lights/main.js
2023-04-16 02:19:49 +03:00
Ask

18 lines
382 B
JavaScript

{ec521c63d9541b2eab96d476e956afa85c4f2b4d true 382 main.js 0xc002b973b0}

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'));
}