Factorialize a Number helpp

Factorialize a Number helpp
0

#1

whats wrong in my code

Your code so far


function factorialize(num) {
if (num == 0 || num == 1){
  num = 1;
}
for (var i = num - 1;i>=1;i--){
  num*=i;
}
return num;
}

factorialize(5);
console.log(num);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number


#2

It the test case of factorialize(5), your current code starts i = 4, then i =3, then i=2, then i = 1. Why did you not include 5?


#3

because num = 5 from before so 5*4 then 3 2 1


#4

Your code isn’t wrong (except it is little annoying to read). Perhaps, reset and re-run the test?


#5

Sorry about that. I thought there was a problem, but realize now that your code does produce the correct result.