title: Trying to understand rövarspråket translator
body: <p>I'm doing a beginner exercise, create a rövarspråket translator. </p>
  
  <blockquote>
    <p>Write a function translate() that will translate a text into
    “rövarspråket”. That is, double every consonant and place an
    occurrence of "o" in between. For example, translate("this is fun")
    should return the string "tothohisos isos fofunon".</p>
  </blockquote>
  
  <p>The solutions I was coming up with were bad, so I found one <a href="https://codereview.stackexchange.com/questions/49375/various-simple-javascript-solutions">here</a> and am trying to understand it.</p>
  
  <pre><code>var translate = function(text) {
    var string = text.toLowerCase();
    var vowels = ["a", "e", "i", "o", "u", " "];
    var y = "";
    for (i = 0; i &lt; string.length; i++) {
       var current = string.charAt(i); 
      if (vowels.indexOf(current) != -1) {
          y = (y + (current));
      } else {
          y = (y + (current + "o" + current));
      }
    }
    return y;
  }
  
  console.log(translate("this is fun"));
  </code></pre>
  
  <ul>
  <li><p>Why does <code>if (vowels.indexOf(current) != -1)</code> need <code>-1</code> specifically? I tried <code>-2</code>, <code>-1000</code>, <code>1000</code>, but they all break the function.</p></li>
  <li><p>If I change <code>y = "";</code> to <code>y = "XYZ"</code>, <code>translate("this is fun")</code> returns "XYZtothohisos isos fofunon". Why is it only before the first consonant and not all of them?</p></li>
  </ul>