title: While loop in Javascript as long as modulo is 0
body: <p>I want to write a function that divides a number n-times as long as the modulo is 0. For instance:</p>
  
  <pre><code>solve (1000) returns 2
  solve (1503) returns 3
  
  </code></pre>
  
  <p>My try</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 solve(n) {
    let counter;
  
    while (n % 500 === 0) {
      counter += n % 500
      n++
    }
    return counter
  }
  
  console.log( solve(1000) )
  console.log( solve(1503) )</code></pre>
  </div>
  </div>
  </p>
  
  <p>When invoked, the function returns 'NaN'. I guess because the while-loop is not applied for some reason. Thanks for reading!</p>