title: Check whether given number is happy or not
body: <p>This is my code to check given number is a <a href="https://en.wikipedia.org/wiki/Happy_number" rel="nofollow noreferrer">Happy number</a>. I think I am trying wrong logic. </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>var num = 5239;
  var sum = 0;
  while (num &gt; 0) {
    sum += Math.pow(num % 10, 2);
    num = Math.floor(num / 10);
    console.log(num)
  }
  console.log(sum);
  if (num == 0) {
    alert("happy number")
  } else {
    alert("Not happy number")
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Please correct me to get correct result.</p>