|
@@ -0,0 +1,53 @@
|
|
|
+/* function green(){
|
|
|
+ console.log('green light');
|
|
|
+ let div = document.getElementById('green');
|
|
|
+ div.style.backgroundColor = 'green'
|
|
|
+
|
|
|
+}
|
|
|
+function yellow(){
|
|
|
+ console.log('yellow light');
|
|
|
+ let div = document.getElementById('yellow');
|
|
|
+ div.style.backgroundColor = 'yellow'
|
|
|
+
|
|
|
+}
|
|
|
+function red(){
|
|
|
+ console.log('red light');
|
|
|
+ let div = document.getElementById('red');
|
|
|
+ div.style.backgroundColor = 'red';
|
|
|
+
|
|
|
+} */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const delay = ms => new Promise(ok => setTimeout(() => ok(ms), ms))
|
|
|
+
|
|
|
+async function trafficLight(parent){
|
|
|
+ /* let parent = document.getElementById('trafficlight'); */
|
|
|
+ for(let i=0; i<3;i++){
|
|
|
+ let div = document.createElement('div')
|
|
|
+ div.classList = 'round';
|
|
|
+ parent.append(div);
|
|
|
+ }
|
|
|
+ while (true){
|
|
|
+ // включаем зеленый
|
|
|
+ parent.children[0].style.backgroundColor = 'green';
|
|
|
+ parent.children[2].style.backgroundColor = '';
|
|
|
+ await delay(4000)
|
|
|
+ // включаем желтый
|
|
|
+ parent.children[0].style.backgroundColor = '';
|
|
|
+ parent.children[1].style.backgroundColor = 'yellow';
|
|
|
+ await delay(3000)
|
|
|
+ // включаем красный
|
|
|
+ parent.children[1].style.backgroundColor = '';
|
|
|
+ parent.children[2].style.backgroundColor = 'red';
|
|
|
+ await delay(4000)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+trafficLight(trafficlight);
|