title: HTML - How to generate a random number in an img=src address inside a div
body: <p>Hi_I’m trying to make a random number appear inside an <code>img src=</code> address in a div, so that a random image is generated every time the div is loaded.</p>
  
  <p>I have 10 images and their directory addresses are:</p>
  
  <pre><code>"pictures/number1.jpg"
  "pictures/number2.jpg"
  "pictures/number3.jpg"
  ................
  "pictures/number10.jpg"
  </code></pre>
  
  <p>I’m able select one of these at random with the following Javascript:</p>
  
  <pre><code>var num = Math.floor(Math.random() * 10 + 1); 
  img.src = "pictures/number" +num +".jpg";
  </code></pre>
  
  <p>This generates a random number between 1 and 10 and places it inside the address to locate the image.
  This works perfectly when the <code>img.src</code> is used inside the Javascript file, but I’m wondering if it’s possible to use this method when <code>img src=</code> is part of a HTML page. I’m trying to apply a similar process to the following HTML code:</p>
  
  <pre><code>&lt;script&gt;
  var num = Math.floor(Math.random() * 10 + 1); 
  randomimage = "pictures/number" +num +".jpg";
  &lt;/script&gt;
  
  &lt;div id="JohnDIV" align="center"&gt; &lt;img src=randomimage alt="If you can see this, then the image didn't load properly" class="myclass1" /&gt; &lt;/div&gt;
  &lt;div id="JackDIV" align="center"&gt; &lt;img src=randomimage alt="If you can see this, then the image didn't load properly" class="myclass1" /&gt; &lt;/div&gt;
  &lt;div id="JaneDIV" align="center"&gt; &lt;img src=randomimage alt="If you can see this, then the image didn't load properly" class="myclass1 /&gt; &lt;/div&gt;
  </code></pre>
  
  <p>This isn't working, it's just showing me the <code>alt=</code> message. I'm not sure if I've defined <code>randomimage</code> correctly. 
  I'm really confused about how to go about doing this the right way, any help would be greatly appreciated!</p>
  
  <p>Thanks in advance!</p>