【勉強を再開する前に】信号機の実現


信号灯を実現し、丸いdivを緑の3秒、黄色の1秒、赤い2秒で背景色を変えます. function keepColor(duration) { return new Promise((resolve, reject) => { setTimeout(resolve, duration); }); } async function changeColor (color, duration) { document.getElementsByClassName('traffic-light')[0].style.background = color; await keepColor(duration); } async function run() { while (1) { await changeColor('green', 3000); // await , await changeColor('yellow', 1000); await changeColor('red', 2000); } } run();