title: Javascript if statement to insert an image
body: <p>I'm very new to Javascript and trying to replicate something I do on a spreadsheet, but in javascript on a webpage, I've got it to work in a long winded way, looking for ways to simplify it.</p>
  
  <p>The script is embedded within the HTML </p>
  
  <pre><code>&lt;td class="td_Col11cSize"&gt;
    &lt;div class="TableText"&gt;
      &lt;span class = "Sub0a"&gt;
        &lt;script type="text/javascript"&gt;
          if (Game2Player4Sub == "")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub1a"&gt;
        &lt;script type="text/javascript"&gt;
          if (Game2Player4Sub == "Sub 1")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub2a"&gt;
        &lt;script type="text/javascript"&gt; 
          if (Game2Player4Sub == "Sub 2")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub3a"&gt;
        &lt;script type="text/javascript"&gt; 
          if (Game2Player4Sub == "Sub 3")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub4a"&gt;
        &lt;script type="text/javascript"&gt;
          if (Game2Player4Sub == "Sub 4")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub5a"&gt;
        &lt;script type="text/javascript"&gt; 
          if (Game2Player4Sub == "Sub 5")
            document.write(Game2Player4Name, Game2Player4Off) 
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub6a"&gt;
        &lt;script type="text/javascript"&gt; 
          if (Game2Player4Sub == "Sub 6")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
      &lt;span class = "Sub7a"&gt;
        &lt;script type="text/javascript"&gt;
          if (Game2Player4Sub == "Sub 7")
            document.write(Game2Player4Name, Game2Player4Off)
        &lt;/script&gt;
      &lt;/span&gt;
    &lt;/div&gt;
  &lt;/td&gt;   
  </code></pre>
  
  <p>The code checks 8 conditions to set the font colour and add a player's name and time taken off in brackets. The above works, but is long winded and need to look at writting a function to replace it as its used 18 x 46 times on the page.</p>
  
  <p>I also need to add another if statement to add <code>&lt;img src ="YellowCard.png"&gt;</code> when <code>(Game2Player4Yellow == "n")</code></p>