I am trying to find a way to calculate the sum of all numbers from 1 to N using JavaScript. Below is the code I tried so far, but it does not work.
function numberSum(N) {
var total = 0;
for(var i = 1; i <= N; i++){
total += i;
}
return total;
}
I tried using jslint and other validators online to check if I could miss something, but this does not seem to help me find the reason why the code is not working. Is there something I am missing that prevents the script from completing the append?
source
share