title: Keep track of how many times a recursive function was called
body: <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 singleDigit(num) {
        let counter = 0
        let number = [...num + ''].map(Number).reduce((x, y) =&gt; {return x * y})
  
        if(number &lt;= 9){
            console.log(number)
        }else{
            console.log(number)
            return singleDigit(number), counter += 1
        }
     }
  singleDigit(39)</code></pre>
  </div>
  </div>
  </p>
  
  <p>The code above takes an integer and reduces it to a single digit by multiplying it by its own digits.</p>
  
  <p>Example is 39.</p>
  
  <pre><code>3 x 9 = 27.
  2 x 7 = 14.
  1 x 4 = 4.
  </code></pre>
  
  <p>The console will log:</p>
  
  <pre><code>27 
  14 
  4
  </code></pre>
  
  <p>How do I keep track that the recursive function was called 3 times?</p>
  
  <p>I have tried adding a counter but it fails to update.
  Would appreciate any help</p>