I have solved the challenge, however, I am a little unclear on why I had to include the initial part of the code (the section that is commented out). Particularly the result -1; line.
function factorialize(num) {
//var i;
// var result;
// result = 1;
for(let i = 1; i <= num; i++){
result = result * i;
}
return result
}
console.log(factorialize(5));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.
Thanks for providing the clarity. One more question: why does the code return a different result depending on where the [ var result = 1 ] declaration is placed? For example, if I declare result = 1 in the for loop block, the function will return something different.