SOURCE

console 命令行工具 X clear

                    
>
console
var light = document.getElementById('light');
green();

function red() {
  light.setAttribute('style','background-color:red')
  setTimeout(() => green(), 1000);
}

function green() {
  light.setAttribute('style','background-color:green')
  setTimeout(() => yellow(), 3000);
}

function yellow() {
  light.setAttribute('style','background-color:yellow')
  setTimeout(() => red(), 2000);
}
<html>
    <body>
        <div id="light" class="light">         
        </div>
    </body>
</html>
.light {
    height: 100px;
    width: 100px;
    border-radius: 50%;
}