What am I doing wrong with this addition code?
var addition=function(num){
var sumSoFar=0;
for(var i=1;i<=num;i++)
{
sumSoFar+=num[i];
return sumSoFar;
}
};
console.log(addition(5));
I wrote this with a while loop a little bit ago. It supposed to take a
random (num) and return the sum of all numbers from 1 to (num) Im just not
figuring out what im doing wrong with the for loop
No comments:
Post a Comment