title: Rotate a string with JavaScript?
body: <p>I have a lot of the basics down, but I'm going through w3resource sample problems (<a href="https://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php" rel="nofollow noreferrer">https://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php</a> - question 5) and I'm really confused. The below code is w3's solution on how to rotate a string. I have 6 questions. If you can help me understand any 1, or all, I'd greatly appreciate it because this novice is struggling.    </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt; 
  &lt;/head&gt;
  &lt;body onload="animate_string('target')" 
  
    &lt;pre id="target"&gt;Look at me move! &lt;/pre&gt;  
  
      &lt;script type="text/javascript"&gt;
  
          function animate_string(id) 
  </code></pre>
  
  <p>1. Why do we write this function (animate_string) with the parameter 'id' when above we already specified the 'id' name and its parameter? </p>
  
  <pre><code>{
      var element = document.getElementById(id); 
      var textNode = element.childNodes[0];
  </code></pre>
  
  <p>2. why do we need childNodes?</p>
  
  <pre><code>        var text = textNode.data;
  </code></pre>
  
  <p>3. Why data?</p>
  
  <pre><code>    setInterval(function () 
  {
   text = text[text.length - 1] + text.substring(0, text.length - 1); 
  </code></pre>
  
  <p>4. Why does it loop?</p>
  
  <pre><code>      textNode.data = text; 
  </code></pre>
  
  <p>5. We already said that text = textNode.data. Why again here?</p>
  
  <pre><code>    }, 100); 
  </code></pre>
  
  <p>6. Why is the closing parenthesis outside of the curly braces?
          }  </p>
  
  <pre><code>    &lt;/script&gt;
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>