title: "Writing" inside a HTML page using JS and JS scope
body: <p>I'm developing a program which basically just receives input from the user twice (risk carrier and sum, but that's just a placeholder to make my program less abstract), groups those two values together and then repeats the contents in a loop. See the code below.</p>
  
  <pre><code>&lt;head&gt;
  
  &lt;script type="text/javascript"&gt;
  function fillArray(){
      document.getElementById("danke").innerHTML = "Thanks for specifying the amount of entries.";
      var numberOfEntries = parseInt(document.getElementById('input0').value);
      var i = 0;
      var myArrA = [];
      var myArrB = [];
      var x = " ";
      while(i&lt;numberOfEntries){
         var neuRT = prompt("Enter a risk carrier");
         myArrA.push(neuRT);
         var neuRH = prompt("Enter a risk sum");
         myArrB.push(neuRH);
         i++;
      }
      for(i = 0; i&lt;anzahlEintraege; i++){
          x = myArrA[i] + " carries a risk of " + myArrB[i];
      document.getElementById("test").innerHTML = x;
      }
  
  }
  
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;h1&gt;risk assessment&lt;/h1&gt;
  
  &lt;input type="text" id="input0" /&gt;
  &lt;button type="button" onclick="fillArray()"&gt;Number of entries&lt;/button&gt; &lt;p id="danke"&gt;&lt;/p&gt;
  
  &lt;button type="button" onclick="untilNow()"&gt;Show all entries so far&lt;/button&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;div id="test"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>My issues are:</p>
  
  <p>1.) I want to display the array by writing into an HTML element, which I attempted in the for-loop. Pop-ups are to be avoided. How can I loop through HTML elements, such as demo1, demo2, demo3 etc.? I can't just write <code>&lt;p id="demo" + i&gt;&lt;/p&gt;</code>. What other options are there?</p>
  
  <p>2.) Say I want to make use of the untilNow() function. The scope of my arrays is limited to fillArray(). Do I need to "return" the arrays to the untilNow() function as parameters? </p>
  
  <p>Thanks everyone!!!</p>