title: Javascript - string capitalization function throwing strange error
body: <p>Stackers, please help my worn out beginner's brain and let me know where I've goofed.</p>
  
  <p>My function accepts a lower case string as its only argument. It is SUPPOSED to return the same string with all even indexed characters in each word uppercase. But the actual output is different to my expected output. </p>
  
  <p>For example:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>console.log(toWeirdCase('harry enjoys reading books'))
  //expected output: 'HaRrY EnJoYs ReAdInG BoOkS'
  // actual output: 'HaRrY EnJoYs ReAdInG BookS'
  
  console.log(toWeirdCase('gooooooogle search in vain'));
  //expected output: 'GoOoOoOoGlE SeArCh In VaIn'
  // actual output: GoooooooGlE SeArCh In VaIn
  
  function toWeirdCase(string) {
      string = string.split(" ");
      for (let i = 0; i &lt; string.length; i++) {
          for (let x = 0; x &lt; string[i].length; x++) {
              if (string[i].indexOf(string[i].charAt(x)) % 2 == 0) {
                  string[i] = string[i].replace(string[i].charAt(x), string[i].charAt(x).toUpperCase());
              }
          }
      }
      return string.join(" ");
  }</code></pre>
  </div>
  </div>
  </p>