title: Where am I going wrong? Trying to print no of times number is added before returning single digit
body: <pre><code>function AdditivePersistence(num) {
      var count = 0;
      while (num.toString().length &gt; 1) {
          count++;
          var num = calcVal(num);
  
      }
      return count;
  
      function calcVal(str) {
          var sum = 0;
          var arr = str.toString().split("");
          for (var i of arr) {
              sum = sum + arr[i];
          }
          return parseInt(sum.toString());
      }
  }
  
  console.log(AdditivePersistence(2233));
  </code></pre>
  
  <p><code>calcValue</code> function returns sum of the array numbers and while loop repeats until returned number length is 1.</p>