title: I have a JS script in my php file, and it does not seem to be executing
body: <p>This started after I converted this same script which was previously laid out in PHP to JS (I tried to change all the syntax.)</p>
  
  <p>I have tried running it how it is within the php file and it didn't work :</p>
  
  <pre><code>    &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Learn | A Level Scientist&lt;/title&gt;
  &lt;link rel="shortcut icon" href="http://www.iconj.com/ico/f/0/f0ghi1ksdc.ico" type="image/x-icon" /&gt;
  &lt;style&gt;
      #menubar {;color:white;font-size:100%;padding-top:5px;padding-bottom:5px;
      border-radius:5px;margin-top: 1%;margin-bottom:1%;margin-left:4%;margin-right:4%; background: rgba(0,73,126,0.6);}
  
      span {margin-left:2.5%;margin-right:2.5%;}
      #mainsection {background: rgba(0,73,126,0.6);color:white;margin-left:4%;margin-right:4%;border-radius:5px;padding-left:20px;padding-right:20px;padding-bottom:0.5%;text-align:center;}
      body {background:radial-gradient(#00477C,#002E4F);}
      #horizsep {width:100%;text-align:center;color:white;padding-top:0%;padding-bottom:0%;margin:0px}
      #copyright{text-align:center;}
      #welcomemsg {font-size:30px;margin:0px;padding:0px}
      #surroundmid{font-size:26px; padding-bottom:160px;}
      #start_learning:hover {width:155px;font-size:22px;color:white;background-color:#5288AB;border-width:0px;border-radius:5px;}
      #tube_part {background-color:#DB2625;margin:0%;}
      #you_part {margin:0%;color:black;border-radius:30px;text-align:center}
      #fb_part {background-color:#3B5998;color:white;margin:0%;text-align:center}
      #acebook_part {background-color:#3B5998;margin:0%}
      a{color:white; underline:none}
      a:hover {color: #4DB849 ; underline:none}
      a:hover {color: #4DB849 ; underline:none}
      a:hover {color: #4DB849 ; underline:none}
      a:clicked {color: white; underline:none}
      *.menubar {border-width:0px;border-radius:1px;background:rgba(0,0,0,0.1);color:white;}
      *.menubar:hover{color:white;background-color:#5288AB;border-width:0px;border-radius:1px;}
      #loginform {display:inline-block;margin:0px}
      #chembutton {width:30%;height:10%;font-size:40px;color:white;background:rgba(17,214,118,0.3);border-width:0px;border-radius:5px;}
      #chembutton:hover {width:32%;height:11%;font-size:45px;color:white;background:rgba(17,214,118,0.5);border-width:0px;border-radius:5px;}
      #chembutton:active {width:33%;height:12%;font-size:45px;color:white;background:rgba(17,214,118,0.7);border-width:0px;border-radius:5px;}
      #ytvid {margin-top:0%;margin-bottom:4.7%}
      #video_navigation_next {width:40%;display:inline-block;}
      #video_navigation_previous {width:40%;display:inline-block;}
      #interface {display:block;width:900px;height:500px;background:rgba(0,46,79,0.4);margin:auto;border-radius:5px;margin-top:5px;margin-bottom:20px;vertical-align:top;}
      #output{width:550px;border-radius:5px;height:450px;background:rgba(47,94,130,0.4);display:inline-block;margin:25px;vertical-align:top;font-size:18px}
      #input{width:250px;border-radius:5px;height:450px;background:rgba(47,94,130,0.4);display:inline-block;margin:25px;margin-left:0px;vertical-align:top;}
      #useranswer {margin-top:40px}
      #helpsection {margin:10%}
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;section&gt;
  
  
  &lt;?php 
      include 'C:\xampp\htdocs\ALevelScientistTesting\menubar.php' ;
  ?&gt;
  
  
  
  &lt;div id="mainsection"&gt;
  &lt;div id="welcomemsg"&gt;&lt;strong&gt;&lt;u&gt; Working out Relative Formula/Molecular Masses &lt;/u&gt;&lt;/strong&gt;&lt;/div&gt;&lt;br&gt;
  &lt;div id="video_navigation_previous"&gt;&lt;a href="makible.php"&gt;&lt;br&gt;&lt;span id="nextvid"&gt; &lt;!-- &lt;= Go to the Previous Exercise --&gt; &lt;span&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;div id="video_navigation_next"&gt;&lt;a href="chlowatreat.php"&gt;&lt;br&gt;&lt;span id="nextvid"&gt; Go to the Next Exercise =&gt; &lt;span&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;div id="interface"&gt;
  &lt;div id="output"&gt;
  
      &lt;?php
       //echo 'The '.$CoMo.' : '.$SubName[$FormNo].' Has a Relative '.$FoMo.' Mass of : '.$x;
      //echo '&lt;br&gt; Work out the Relative '.$FoMo.' Mass of the '.$CoMo.' : '.$SubName[$FormNo] ;
      ?&gt;
  
      &lt;script type="text/javascript"&gt;
  
       document.write('The Program got to here...');
  
    //The following 3 Arrays store 3 things. 1) The Element names. 2) The element Symbols. 3) The Relative Atomic Masses of the Elements.
      var Elements = new Array("Hydrogen","Lithium","Sodium","Potassium","Rubidium","Caesium","Francium","Beryllium","Magnesium","Calcium","Strontium","Barium","Radium","Scandium","Yttrium","Lanthanum","Actinium","Titanium","Zirconium","Halfnium","Rutherfordium","Vanadium","Niobium","Tantalum","Dubnium","Chromium","Molybdenum","Tungsten","Seaborgium","Manganese","Technetium","Rhenium","Bohrium","Iron","Ruthenium","Osmium","Hassium","Cobalt","Rhodium","Iridium","Meitnerium","Nickel","Palladium","Platinum","Darmstadtium","Copper","Silver","Gold","Roentgenium","Zinc","Cadmium","Mercury","Boron","Aluminum","Gallium","Indium","Thallium","Carbon","Silicon","Germanium","Tin","Lead","Nitrogen","Phosphorus","Arsenic","Antimony","Bismuth","Oxygen","Sulfur","Selenium","Tellurium","Polonium","Flourine","Chlorine","Bromine","Iodine","Astatine","Helium","Neon","Argon","Krypton","Xenon","Radon");
      var ElementsSym = new Array("H","Li","Na","K","Rb","Cs","Fr","Be","Mg","Ca","Sr","Ba","Ra","Sc","Y","La","Ac","Ti","Zr","Hf","Rf","V","Nb","Ta","Db","Cr","Mo","W","Sg","Mn","Tc","Re","Bh","Fe","Ru","Os","Hs","Co","Rh","Ir","Mt","Ni","Pd","Pt","Ds","Cu","Ag","Au","Rg","Zn","Cd","Hg","B","Al","Ga","In","Tl","C","Si","Ge","Sn","Pb","N","P","As","Sb","Bi","O","S","Se","Te","Po","F","Cl","Br","I","At","He","Ne","Ar","Kr","Xe","Rn");
      var ElementsRAM = new Array("1.0","6.9","23.0","39.1","85.5","132.9","223","9.0","24.3","40.1","87.6","137.3","226","45.0","88.9","138.9","227","47.9","91.2","178.5","261","50.9","92.9","180.9","262","52.0","95.9","183.8","266","54.9","98","186.2","264","55.8","101.1","190.2","277","58.9","102.9","192.2","268","58.7","106.4","195.1","271","63.5","107.9","197.0","272","65.4","112.4","200.6","10.8","27.0","69.7","114.8","204.4","12.0","28.1","72.6","118.7","207.2","14.0","31.0","74.9","121.8","209.0","16.0","32.1","79.0","127.6","209","19.0","35.5","79.9","126.9","210","4.0","20.2","39.9","83.8","131.3","222");
  
      // The following 3 arrays store all of the molecule names and formulas, along with the subscripted versions of all of the formulas.
      var CompoundsFormula = new Array("Al2O3","NH4N3","NH4ClO3","NH4ClO4","BaCrO4","BeCO3","C6H12N2O4Pt","CrO2F2","C3Cl3N3","GaP","LiCoO2","FeLiO4P","Li2SO4","OF2","KCaCl3","Ag2CrO4","AgBF4","H3NO3S","ZnBr2","Na2CO3","BaFe2O4","BrF5","CaCrO4","H2CO3","MgCO3","AgClO3","Ag3PO4","NaPO2H2","NaMnO4","Na2S2O8");
      var CompoundsName = new Array("Aluminium oxide","Ammonium azide","Ammonium chlorate","Ammonium perchlorate","Barium chromate","Beryllium carbonate","Carboplatin","Chromyl fluoride","Cyanuric chloride","Gallium phosphide","Lithium cobalt oxide","Lithium iron phosphate","Lithium sulfate","Oxygen difluoride","Potassium calcium chloride","Silver chromate","Silver fluoroborate","Sulfamic acid","Zinc bromide","Sodium carbonate","Barium ferrite","Bromine pentafluoride","Calcium chromate","Carbonic acid","Magnesium carbonate","Silver chlorate","Silver orthophosphate","Sodium hypophosphite","Sodium permanganate","Sodium persulfate");
      var SubCompoundsArray = new Array("Al&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;ClO&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;ClO&lt;sub&gt;4&lt;/sub&gt;","BaCrO&lt;sub&gt;4&lt;/sub&gt;","BeCO&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;Pt","CrO&lt;sub&gt;2&lt;/sub&gt;F&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;Cl&lt;sub&gt;3&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;","GaP","LiCoO&lt;sub&gt;2&lt;/sub&gt;","FeLiO&lt;sub&gt;4&lt;/sub&gt;P","Li&lt;sub&gt;2&lt;/sub&gt;SO&lt;sub&gt;4&lt;/sub&gt;","OF&lt;sub&gt;2&lt;/sub&gt;","KCaCl&lt;sub&gt;3&lt;/sub&gt;","Ag&lt;sub&gt;2&lt;/sub&gt;CrO&lt;sub&gt;4&lt;/sub&gt;","AgBF&lt;sub&gt;4&lt;/sub&gt;","H&lt;sub&gt;3&lt;/sub&gt;NO&lt;sub&gt;3&lt;/sub&gt;S","ZnBr&lt;sub&gt;2&lt;/sub&gt;","Na&lt;sub&gt;2&lt;/sub&gt;CO&lt;sub&gt;3&lt;/sub&gt;","BaFe&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","BrF&lt;sub&gt;5&lt;/sub&gt;","CaCrO&lt;sub&gt;4&lt;/sub&gt;","H&lt;sub&gt;2&lt;/sub&gt;CO&lt;sub&gt;3&lt;/sub&gt;","MgCO&lt;sub&gt;3&lt;/sub&gt;","AgClO&lt;sub&gt;3&lt;/sub&gt;","Ag&lt;sub&gt;3&lt;/sub&gt;PO&lt;sub&gt;4&lt;/sub&gt;","NaPO&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;","NaMnO&lt;sub&gt;4&lt;/sub&gt;","Na&lt;sub&gt;2&lt;/sub&gt;S&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;8&lt;/sub&gt;");
  
      // The following 3 arrays store all the compound names and formulas, along with the subscripted versions of all the formulas.
      var MoleculesFormula = new Array("C15H20O4","C12H8","CH3CO2Na","C3H4O2","C60","C6H12O6","C5H9N1O4","C5H8O4","CN","H2O2","C13H18O2","C12H22O11","C14H14O3","C10H8","C14H18N2O5","C18H22O2","C3H3O3","C7H5N1O3S1","C5H6N2O2","C3H9N","C16H13Cl1N2O1","C19H16O4","C6H3N3O6","C8H8O3","C21H22N2O2","C6H14O6","C9H11N1O6","C10H20O1","C8N8O16","C6H6N12O12","C6H5NO2");
      var MoleculesName = new Array("Abscisic acid","Acenaphthylene","Sodium acetate","Acroleic acid","Buckminsterfullerene","Fructose","Glutamate","Glutaric acid","Hydrogen Cyanide","Hydrogen Peroxide","Ibuprofen","Beta-Lactose","Naproxen","Naphthalene","Aspartame","Estrone","Pyruvate","Saccharin","Thymine","Trimethylamine","Diazepam","Warfarin","Trinitrobenzene","Vanillin","Strychnine","Sorbitol","Showdomycin","Menthol","Octanitrocubane","Hexanitrohexaazaisowurtzitane","Nitrobenzene");
      var SubMoleculesArray = new Array("C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;","CH&lt;sub&gt;3&lt;/sub&gt;CO&lt;sub&gt;2&lt;/sub&gt;Na","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;9&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","CN","H&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;5&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;3&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;7&lt;/sub&gt;H&lt;sub&gt;5&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;S&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;6&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;9&lt;/sub&gt;N","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;3&lt;/sub&gt;Cl&lt;sub&gt;1&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;9&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;3&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;8&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;"," C&lt;sub&gt;9&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;8&lt;/sub&gt;N&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;6&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;5&lt;/sub&gt;NO&lt;sub&gt;2&lt;/sub&gt;");
  
      //The following part is the section where the specific Formula will be randomly selected for the questions.
  
      var MCselection = Math.floor(Math.random()*2);
      document.write(MCselection);
  
      if(MCselection == 0) {
       var Formula = CompoundsFormula;
       var Name = CompoundsName;
       var SubName = SubCompoundsArray;
       var CoMo = 'Compound';
       var FoMo = 'Formula';
      } else {
       var Formula = MoleculesFormula;
       var Name = MoleculesName;
       var SubName = SubMoleculesArray;
       var CoMo = 'Molecule';
       var FoMo = 'Molecular';
      }
  
      var FormNo = Math.floor(Math.random()*30);
      var Form = Formula[FormNo];
      var FormName = Name[FormNo];
      var FormSub = SubName[FormNo];
      var ElementSub = new Array();
      var FoRAM = new Array();
      var ElemProduct = new Array();
  // Note : This is the substring Syntax : ACTUAL_STRINGHERE.substr(start,length)
  // Note : is_numeric will return TRUE if the substring in question is a number. False Otherwise.
      var l = 0;
      var y = 0;
  // The following Code is going to strip away the elements and each corresponding number of moles
  // of each element per unit compound/molecule into separate arrays.
   while (l &lt; Form.length)) {
      if(Form.substr(l+1,1).toLowerCase()==Form.substr(l+1,1) || !isNaN(Form.substr(l+1,1))) {
          if (!isNaN(Form.substr(l+1,1))) {
              Element[y] =  Form.substr(l,1);
              if (!isNaN(Form.substr(l+2,1))) {
                      ElementSub[y] = Form.substr(l+1,2);
                      l++;
                      l++;
                  } else {
                      ElementSub[y] = Form.substr(l+1,1);
                      l++;
          }
      } else {
              Element[y] = Form.substr(l,2);
  
              if (!isNaN(Form.substr(l+2,1))) {
                  if (!isNaN(Form.substr(l+3,1))) {
                      ElementSub[y] = Form.substr(l+2,2);
                      l+=3;
                  } else {
                      ElementSub[y] = Form.substr(l+2,1);
                      l+=2;
                  }
              } else {
                  ElementSub[y] = 1;
                  l++;
              }
          }
      } else {
          Element[y] = Form.substr(l,1);
          ElementSub[y] = 1;
      }
       l++;
       y++;
  
      }
  
      // this resets the value of $l to 0 so that it can be recycled for another while loop.
      l = 0;
      x = 0;
      // The following Code Identifies The Different Elements Present in the Array.
      while(x &lt; Element.length) {
      while(l &lt; ElementsSym.length) {
          if (ElementsSym[l]==Element[x]) {
              FoRAM[x] = ElementsRAM[l];
          }
          l++;
      }
          l = 0;
          x++;
      }
  
      // this also resets the value of $l to 0 so that it can be recycled for another while loop.
  
      l = 0;
      x = 0;
  
      // This find the product of each element multiplied by the number of moles present per mole of the formula.
  
      while(l&lt;Element.length) {
      ElemProduct[l] = FoRAM[l]*ElementSub[l];
  //      echo '&lt;br&gt;';
          l++;
      }
      // This finds the total of all the molar elemental products b adding up the values in an array.
          //x = array_sum(ElemProduct);
  
  var n   = 0;
  var sum = 0;
  
  while(n&lt;ElemProduct.length) {
     sum += ElemProduct[n];
     n++;
     }
  
  
  document.write("The " + CoMo + " : " + SubName[FormNo] + " Has a Relative " + FoMo + " Mass of : " + sum );
  
      // The following Line Presents the Information.
  
      &lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
      &lt;/script&gt;
      &lt;br&gt;&lt;hr&gt;
  &lt;/div&gt;
  &lt;div id="input"&gt;
  
      &lt;form id="useranswer"&gt;
          Enter Your Answer Here&lt;br&gt;
          &lt;input type="text" id="useranswer"&gt;&lt;br&gt;
          &lt;input type="submit" id="usersubmit" value="Check Answer"&gt;
  
      &lt;/form&gt;
  
      &lt;div id="helpsection"&gt;
      &lt;hr&gt;&lt;br&gt;
      Not sure what Relative Formula mass is? &lt;br&gt;
      &lt;a&gt;Click Here.&lt;/a&gt; &lt;br&gt;
      Not sure what Relative Molecular mass is?&lt;br&gt;
      &lt;a&gt;Click Here.&lt;/a&gt;
      &lt;br&gt;
      &lt;hr&gt;
      &lt;br&gt;
      Haven't learned how to work this out yet? &lt;br&gt;
      &lt;a&gt;Click Here.&lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
   &lt;/div&gt;
  &lt;hr&gt;
  &lt;span id="copyright"&gt; Copyright A Level Scientist 2014 | All rights reserved. &lt;span&gt;
  &lt;/div&gt;
  
  &lt;/section&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I run this code at the moment, the result looks like this :</p>
  
  <p><a href="http://postimg.org/image/6993cuaqb/" rel="nofollow">http://postimg.org/image/6993cuaqb/</a></p>
  
  <p>Can someone please explain to me what is wrong with the code at the moment ! Thank you :)</p>
  
  <p>---EDIT /</p>
  
  <p>This is my new script, it kind of works, but does not. If someone would kindly test it you may get an insight into what i'm talking about (NAN, Long decimals.). When you're testing it, refresh multiple times and look at what happens.</p>
  
  <p>New Script : </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
  
    //The following 3 Arrays store 3 things. 1) The Element names. 2) The element Symbols. 3) The Relative Atomic Masses of the Elements.
      var Elements = new Array("Hydrogen","Lithium","Sodium","Potassium","Rubidium","Caesium","Francium","Beryllium","Magnesium","Calcium","Strontium","Barium","Radium","Scandium","Yttrium","Lanthanum","Actinium","Titanium","Zirconium","Halfnium","Rutherfordium","Vanadium","Niobium","Tantalum","Dubnium","Chromium","Molybdenum","Tungsten","Seaborgium","Manganese","Technetium","Rhenium","Bohrium","Iron","Ruthenium","Osmium","Hassium","Cobalt","Rhodium","Iridium","Meitnerium","Nickel","Palladium","Platinum","Darmstadtium","Copper","Silver","Gold","Roentgenium","Zinc","Cadmium","Mercury","Boron","Aluminum","Gallium","Indium","Thallium","Carbon","Silicon","Germanium","Tin","Lead","Nitrogen","Phosphorus","Arsenic","Antimony","Bismuth","Oxygen","Sulfur","Selenium","Tellurium","Polonium","Flourine","Chlorine","Bromine","Iodine","Astatine","Helium","Neon","Argon","Krypton","Xenon","Radon");
      var ElementsSym = new Array("H","Li","Na","K","Rb","Cs","Fr","Be","Mg","Ca","Sr","Ba","Ra","Sc","Y","La","Ac","Ti","Zr","Hf","Rf","V","Nb","Ta","Db","Cr","Mo","W","Sg","Mn","Tc","Re","Bh","Fe","Ru","Os","Hs","Co","Rh","Ir","Mt","Ni","Pd","Pt","Ds","Cu","Ag","Au","Rg","Zn","Cd","Hg","B","Al","Ga","In","Tl","C","Si","Ge","Sn","Pb","N","P","As","Sb","Bi","O","S","Se","Te","Po","F","Cl","Br","I","At","He","Ne","Ar","Kr","Xe","Rn");
      var ElementsRAM = new Array(1.0,6.9,23.0,39.1,85.5,132.9,223,9.0,24.3,40.1,87.6,137.3,226,45.0,88.9,138.9,227,47.9,91.2,178.5,261,50.9,92.9,180.9,262,52.0,95.9,183.8,266,54.9,98,186.2,264,55.8,101.1,190.2,277,58.9,102.9,192.2,268,58.7,106.4,195.1,271,63.5,107.9,197.0,272,65.4,112.4,200.6,10.8,27.0,69.7,114.8,204.4,12.0,28.1,72.6,18.7,207.2,14.0,31.0,74.9,121.8,209.0,16.0,32.1,79.0,127.6,209,19.0,35.5,79.9,126.9,210,4.0,20.2,39.9,83.8,131.3,222);
      // The following 3 arrays store all of the molecule names and formulas, along with the subscripted versions of all of the formulas.
      var CompoundsFormula = new Array("Al2O3","NH4N3","NH4ClO3","NH4ClO4","BaCrO4","BeCO3","C6H12N2O4Pt","CrO2F2","C3Cl3N3","GaP","LiCoO2","FeLiO4P","Li2SO4","OF2","KCaCl3","Ag2CrO4","AgBF4","H3NO3S","ZnBr2","Na2CO3","BaFe2O4","BrF5","CaCrO4","H2CO3","MgCO3","AgClO3","Ag3PO4","NaPO2H2","NaMnO4","Na2S2O8");
      var CompoundsName = new Array("Aluminium oxide","Ammonium azide","Ammonium chlorate","Ammonium perchlorate","Barium chromate","Beryllium carbonate","Carboplatin","Chromyl fluoride","Cyanuric chloride","Gallium phosphide","Lithium cobalt oxide","Lithium iron phosphate","Lithium sulfate","Oxygen difluoride","Potassium calcium chloride","Silver chromate","Silver fluoroborate","Sulfamic acid","Zinc bromide","Sodium carbonate","Barium ferrite","Bromine pentafluoride","Calcium chromate","Carbonic acid","Magnesium carbonate","Silver chlorate","Silver orthophosphate","Sodium hypophosphite","Sodium permanganate","Sodium persulfate");
      var SubCompoundsArray = new Array("Al&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;ClO&lt;sub&gt;3&lt;/sub&gt;","NH&lt;sub&gt;4&lt;/sub&gt;ClO&lt;sub&gt;4&lt;/sub&gt;","BaCrO&lt;sub&gt;4&lt;/sub&gt;","BeCO&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;Pt","CrO&lt;sub&gt;2&lt;/sub&gt;F&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;Cl&lt;sub&gt;3&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;","GaP","LiCoO&lt;sub&gt;2&lt;/sub&gt;","FeLiO&lt;sub&gt;4&lt;/sub&gt;P","Li&lt;sub&gt;2&lt;/sub&gt;SO&lt;sub&gt;4&lt;/sub&gt;","OF&lt;sub&gt;2&lt;/sub&gt;","KCaCl&lt;sub&gt;3&lt;/sub&gt;","Ag&lt;sub&gt;2&lt;/sub&gt;CrO&lt;sub&gt;4&lt;/sub&gt;","AgBF&lt;sub&gt;4&lt;/sub&gt;","H&lt;sub&gt;3&lt;/sub&gt;NO&lt;sub&gt;3&lt;/sub&gt;S","ZnBr&lt;sub&gt;2&lt;/sub&gt;","Na&lt;sub&gt;2&lt;/sub&gt;CO&lt;sub&gt;3&lt;/sub&gt;","BaFe&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","BrF&lt;sub&gt;5&lt;/sub&gt;","CaCrO&lt;sub&gt;4&lt;/sub&gt;","H&lt;sub&gt;2&lt;/sub&gt;CO&lt;sub&gt;3&lt;/sub&gt;","MgCO&lt;sub&gt;3&lt;/sub&gt;","AgClO&lt;sub&gt;3&lt;/sub&gt;","Ag&lt;sub&gt;3&lt;/sub&gt;PO&lt;sub&gt;4&lt;/sub&gt;","NaPO&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;","NaMnO&lt;sub&gt;4&lt;/sub&gt;","Na&lt;sub&gt;2&lt;/sub&gt;S&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;8&lt;/sub&gt;");
  
      // The following 3 arrays store all the compound names and formulas, along with the subscripted versions of all the formulas.
      var MoleculesFormula = new Array("C15H20O4","C12H8","CH3CO2Na","C3H4O2","C60","C6H12O6","C5H9N1O4","C5H8O4","CN","H2O2","C13H18O2","C12H22O11","C14H14O3","C10H8","C14H18N2O5","C18H22O2","C3H3O3","C7H5N1O3S1","C5H6N2O2","C3H9N","C16H13Cl1N2O1","C19H16O4","C6H3N3O6","C8H8O3","C21H22N2O2","C6H14O6","C9H11N1O6","C10H20O1","C8N8O16","C6H6N12O12","C6H5NO2");
      var MoleculesName = new Array("Abscisic acid","Acenaphthylene","Sodium acetate","Acroleic acid","Buckminsterfullerene","Fructose","Glutamate","Glutaric acid","Hydrogen Cyanide","Hydrogen Peroxide","Ibuprofen","Beta-Lactose","Naproxen","Naphthalene","Aspartame","Estrone","Pyruvate","Saccharin","Thymine","Trimethylamine","Diazepam","Warfarin","Trinitrobenzene","Vanillin","Strychnine","Sorbitol","Showdomycin","Menthol","Octanitrocubane","Hexanitrohexaazaisowurtzitane","Nitrobenzene");
      var SubMoleculesArray = new Array("C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;","CH&lt;sub&gt;3&lt;/sub&gt;CO&lt;sub&gt;2&lt;/sub&gt;Na","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;9&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","CN","H&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;5&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;8&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;3&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;7&lt;/sub&gt;H&lt;sub&gt;5&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;S&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;5&lt;/sub&gt;H&lt;sub&gt;6&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;3&lt;/sub&gt;H&lt;sub&gt;9&lt;/sub&gt;N","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;3&lt;/sub&gt;Cl&lt;sub&gt;1&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;9&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;O&lt;sub&gt;4&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;3&lt;/sub&gt;N&lt;sub&gt;3&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;8&lt;/sub&gt;H&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;3&lt;/sub&gt;","C&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;N&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;4&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;"," C&lt;sub&gt;9&lt;/sub&gt;H&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;1&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;O&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;H&lt;sub&gt;2&lt;/sub&gt;&lt;sub&gt;0&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;","C&lt;sub&gt;8&lt;/sub&gt;N&lt;sub&gt;8&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;6&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;6&lt;/sub&gt;N&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;O&lt;sub&gt;1&lt;/sub&gt;&lt;sub&gt;2&lt;/sub&gt;","C&lt;sub&gt;6&lt;/sub&gt;H&lt;sub&gt;5&lt;/sub&gt;NO&lt;sub&gt;2&lt;/sub&gt;");
  
      //The following part is the section where the specific Formula will be randomly selected for the questions.
  
      var MCselection = Math.floor(Math.random()*2);
  
      if(MCselection === 0) {
       var Formula = CompoundsFormula;
       var Name = CompoundsName;
       var SubName = SubCompoundsArray;
       var CoMo = 'Compound';
       var FoMo = 'Formula';
      } else {
       var Formula = MoleculesFormula;
       var Name = MoleculesName;
       var SubName = SubMoleculesArray;
       var CoMo = 'Molecule';
       var FoMo = 'Molecular';
      }
  
  
      var FormNo = Math.floor(Math.random()*30);
      var Form = Formula[FormNo];
      var FormName = Name[FormNo];
      var FormSub = SubName[FormNo];
      var ElementSub = new Array();
      var FoRAM = new Array();
      var ElemProduct = new Array();
      var Element = new Array();
  // Note : This is the substring Syntax : ACTUAL_STRINGHERE.substr(start,length)
  // Note : is_numeric will return TRUE if the substring in question is a number. False Otherwise.
      var l = 0;
      var y = 0;
  
  // The following Code is going to strip away the elements and each corresponding number of moles
  // of each element per unit compound/molecule into separate arrays.
   while (l &lt;= Form.length) {
      if((Form.substr(l+1,1).toLowerCase()==Form.substr(l+1,1)) || (!isNaN(Form.substr(l+1,1)))) {
          if (!isNaN(Form.substr(l+1,1))) {
              Element[y] =  Form.substr(l,1);
              if (!isNaN(Form.substr(l+2,1))) {
                      ElementSub[y] = Form.substr(l+1,2);
                      l++;
                      l++;
                  } else {
                      ElementSub[y] = Form.substr(l+1,1);
                      l++;
          }
      } else {
              Element[y] = Form.substr(l,2);
              if (!isNaN(Form.substr(l+2,1))) {
                  if (!isNaN(Form.substr(l+3,1))) {
                      ElementSub[y] = Form.substr(l+2,2);
                      l+=3;
                  } else {
                      ElementSub[y] = Form.substr(l+2,1);
                      l+=2;
                  }
              } else {
                  ElementSub[y] = 1;
                  l++;
              }
          }
      } else {
          Element[y] = Form.substr(l,1);
  
          ElementSub[y] = 1;
      }
       l++;
       y++;
  
      }
  
      document.write(Element);
      // this resets the value of $l to 0 so that it can be recycled for another while loop.
      l = 0;
      x = 0;
      // The following Code Identifies The Different Elements Present in the Array.
      while(x &lt; Element.length) {
      while(l &lt; ElementsSym.length) {
          if (ElementsSym[l]==Element[x]) {
              FoRAM[x] = ElementsRAM[l];
          }
          l++;
      }
          l = 0;
          x++;
      }
  
      // this also resets the value of $l to 0 so that it can be recycled for another while loop.
  
      l = 0;
      x = 0;
  
      // This find the product of each element multiplied by the number of moles present per mole of the formula.
  
      while(l&lt;Element.length) {
      ElemProduct[l] = FoRAM[l]*ElementSub[l];
  //      echo '&lt;br&gt;';
          l++;
      }
      // This finds the total of all the molar elemental products b adding up the values in an array.
          //x = array_sum(ElemProduct);
  
  var n   = 0;
  var sum = 0;
  
  while(n&lt;ElemProduct.length) {
     sum += ElemProduct[n];
     n++;
     }
  
  document.write("&lt;br&gt; The " + CoMo + " : " + SubName[FormNo] + " Has a Relative " + FoMo + " Mass of : " + sum );
  
      // The following Line Presents the Information.
      &lt;/script&gt;
  &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>can someone please point me in the right direction as to why this is happening. Thank you.</p>