title: Recursive function solving
body: <p>Not sure why when this is ran it prints both of the dot's in the array at the same time. Why does it not print dot pause then print dash then dot. Is my conditional written wrong?</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>function morseCode(code) {
    if (code.length === 0) {
      return;
    }
    let ele = code[code.length - 1];
    if (ele === "dot") {
      setTimeout(() =&gt; {
        console.log("dot");
      }, 100);
    } else {
      setTimeout(() =&gt; {
        console.log("dash");
      }, 300);
    }
    return morseCode(code.slice(0, -1));
  }
  let code = ["dot", "dash", "dot"];
  
  morseCode(code);
  // print 'dot'
  // pause for 100ms
  // print 'dash'
  // pause for 300ms
  // print 'dot'
  // pause for 100ms</code></pre>
  </div>
  </div>
  </p>