title: Javascript - Force specific data type input OR accept only digits in input
body: <p>Just starting out on my coding journey. I have this prompt and I'm trying to force the user to only input numbers. any other characters are not allowed. Any idea how I can do this? </p>
  
  <pre><code>var num = prompt("Enter number");
  </code></pre>
  
  <p>I've tried</p>
  
  <pre><code>var num=Number(prompt("Enter number"));
  </code></pre>
  
  <p>I've also tried making a loop like this but i know prompt returns a string:</p>
  
  <pre><code>while (typeof(num)!=='number'{
          alert("You did not enter a number);
          var num=prompt("Enter number"));}
  </code></pre>
  
  <p>I've also tried: </p>
  
  <pre><code>var num= Number(prompt("Enter number"));
  while (num===/==NaN){
          alert("You did not enter a number);
          var num=Number(prompt("Enter number"));}
  alert("You did enter a number");   
  </code></pre>
  
  <p>Entering any non number characters into the Number prompt results in NaN, so I thought that if the answer is NaN every time non-numerical characters are entered, then the loop would trigger, and otherwise it wouldn't but that doesn't seem to be the case for some reason. Any help would be appreciated :)</p>