Pages

Saturday, February 27, 2016

FACTORIALIZE A NUMBER

Challenge here is to return the factorial of the provided integer.

If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120


This challenge requires a thorough knowledge of loops, and how to store the value returned by a loop. In my case "result" is storing variable after ever loop.

It took me a while I was looping correctly, but not storing the result. Getting very high output due to multiplication.

 Here is my solution:


 function factorialize(num) {
   result = 1;
   for (var i = 1; i <= num; i++){
    result *= i;
  }
  return result;
}

factorialize(5);

No comments:

Post a Comment