title: Javascript prompt and alert inputting a number and it will loop and you will input numbers to get the average of it
body: <p>I have below javascript code with loop but I can't get the average of it. I'm not sure what's wrong with my code. It's like the first prompt you will input a number and it will loop and you input numbers like how much you entered and you will get the sum of all the numbers and get the average of it after it's done. Here's the code that I have.</p>
  
  <p>function show_prompt()
      {</p>
  
  <pre><code>    var n=prompt("Input a number: ", "Number here");
      if (n==n)
      {
        var i=1;
        do
        {
          var g=prompt("Input grade: " );
  
          var grade=parseInt(g);
          var total=grade+grade;
          i++;
  
        }
        while(i&lt;=n);
      }
      var average=(total)/n;
      document.write("Average is: " +average);
  }
  </code></pre>
  
  <p>Thanks in advance!</p>