hey i'm just learning javascript in college and our lecturer has given us some questions but there is one i'm totally stumped on.
i know the solution is VERY VERY simple but you know yourselves sometimes when the solution stare you in the face you still can get it.
here's the question
Write JavaScript that calculates the sum and product of all numbers from 1 to some user provided number. Print the results to the page.
so for the sum i was thinking something like this
bit of pseudocode:
for the product is where i'm getting stumped. is multiplying the numbers from 1 to n the same as n factorial? i'm clueless on how to implement this as i tuned out whilst factorial was covered as i don't see a major benefit of it.
any help is appreciated.
i know the solution is VERY VERY simple but you know yourselves sometimes when the solution stare you in the face you still can get it.
here's the question
Write JavaScript that calculates the sum and product of all numbers from 1 to some user provided number. Print the results to the page.
so for the sum i was thinking something like this
bit of pseudocode:
Code:
number= ask user for it
for(i = 0 ; i < number ; i++)
{
sum += i ;
}
for the product is where i'm getting stumped. is multiplying the numbers from 1 to n the same as n factorial? i'm clueless on how to implement this as i tuned out whilst factorial was covered as i don't see a major benefit of it.
any help is appreciated.