Traffic light cycles forever but skips a color, why
const lights = ['red', 'yellow', 'green'];
let index = 0;
function nextLight() {
const current = lights[index];
console.log('Now showing:', current);
switch (current) {
case 'red':
index = 1;
break;
case 'yellow':
index = 2;
case 'green':
index = 0;
break;
}
}
setInterval(nextLight, 1000);
Reply with what is broken and how you would fix it.