Светофор для машин.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <main id="main" style="width: max-content;">Светофор для машин</main>
  11. <script>
  12. const delay = ms => new Promise(ok => setTimeout(() => ok(ms), ms))
  13. let divGreen = document.createElement('div')
  14. let divYelow = document.createElement('div')
  15. let divRed = document.createElement('div')
  16. async function trafficLight(domElement,timeGreen,timeYelow,timeRed){
  17. divGreen.style="background-color: rgb(1, 51, 1) ;"
  18. divYelow.style="background-color: rgb(105, 111, 1) ;"
  19. divRed.style="background-color: rgb(97, 2, 2) ;"
  20. let greenOn =()=> divGreen.style="background-color: rgb(0, 216, 0) ;"
  21. let greenOf =()=> divGreen.style="background-color: rgb(12, 105, 12) ;"
  22. let yelowOf =()=> divYelow.style="background-color: rgb(105, 111, 1) ;"
  23. let yelowOn =()=> divYelow.style="background-color: rgb(202, 216, 0) ;"
  24. let redOn =()=> divRed.style="background-color: rgb(216, 0, 0) ;"
  25. let redOf =()=> divRed.style="background-color: rgb(139, 7, 7);"
  26. divGreen.innerText='Зеленый'
  27. divYelow.innerText='Желтый'
  28. divRed.innerText='Красный'
  29. domElement.append(divGreen,divYelow,divRed)
  30. while (true){
  31. yelowOf()
  32. redOn()
  33. await delay(timeRed)
  34. redOf()
  35. yelowOn()
  36. await delay(timeYelow)
  37. yelowOf()
  38. greenOn()
  39. await delay(timeGreen)
  40. greenOf()
  41. yelowOn()
  42. await delay(timeYelow)
  43. }
  44. }
  45. trafficLight(document.getElementById('main'),5000,1000,5000)
  46. </script>
  47. </body>
  48. </html>