JavaScript Program to find out the sum of first N numbers

Write a JavaScript program using while statement to find out the sum of first n numbers.



Source Code
<html>
<head>
	<title>Sum of fist n numbers</title>
</head>
<body>
<script>
  var i = 1;
	var sum = 0;
  var n = parseInt(prompt("Enter upto which u want to find sum of numbers"))
  
  while(i <= n)
  {
    sum = sum + i;
    i++;
  }
  document.write("Sum of first " + n + " numbers : " + sum);
</script>
</body>
</html>
Output