title: Traffic light using javascript
body: <p>I want create traffic light controller.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;isiqfor&lt;/title&gt;
      &lt;link rel="stylesheet" href="style.css"&gt;
  &lt;/head&gt;
  &lt;body onload="timer;"&gt;
  
  &lt;div id="isiqfor"&gt;
      &lt;div class="green"&gt;&lt;/div&gt;
      &lt;div class="yellow"&gt;&lt;/div&gt;
      &lt;div class="red"&gt;&lt;/div&gt;
  
  &lt;/div&gt;
      &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>CSS code:</p>
  
  <pre><code>#isiqfor{
      border: 10px solid black;
      padding: 10px 3px;
      width: 50px;
  }
  #isiqfor&gt;div{
      width:50px;
      height: 50px;
      border-radius: 50%;
      opacity: .3;
  }
  .green{
      background-color: green;
  }
  .yellow{
      background-color: yellow;
  }
  .red{
      background-color: red;
  }
  </code></pre>
  
  <p>And JS file:</p>
  
  <pre><code>function myFun () {
      // body... 
      var green=document.getElementsByClassName("green")[0];
      var red=document.getElementsByClassName("red")[0];
      var yellow=document.getElementsByClassName("yellow")[0];
  
      green.style.opacity=1;
      setTimeout(function () {
          /* body... */
          green.style.opacity=.3;
          red.style.opacity=.3;
          yellow.style.opacity=1;
      },5000);
  
      setTimeout(function () {
          /* body... */
          green.style.opacity=.3;
          red.style.opacity=1;
          yellow.style.opacity=.3;
      },7000);
  
      setTimeout(function () {
          /* body... */
          green.style.opacity=1;
          red.style.opacity=.3;
          yellow.style.opacity=.3;
      },12000);
  
  
  }
  
  var timer = setInterval(function () {
      /* body... */
      myFun()
  },13000);
  </code></pre>
  
  <p>But problem is when page loads it must wait 13 second for beginning traffic light.How can solve this problem? I want when page loads green light has switched.</p>