Sorry guys but i have a bit of a dumb question for the life of me I cannot get my head around the following
function sumFirstN(n) {
let sum = 0;
if ( n < 0 ) {
sum = NaN;
} else {
for ( let i = 1;i <= n;i += 1){
sum += i;
}
}
return sum;
}
sumFirstN(5)
15
my question is how does the output = 15 i just dont get it ??
I understand it is a loop but i dont see how it came to equallying 15
if i = 1; i <= n(which i presume is now 5); 1+=1
sum +=1
i dont understand how it gets to 15