JS Challenge "Factorialize a Number" Solved but no Brownie points :( [CODE SPOILERS]

Hi there!

Today I solved the challenge called “Factorialize a Number” using this code:

var result = 1;

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

factorialize(5);

Which solves the challenge´s tests, returning the values specified, but for some reason, the tests don´t check out. Any thoughts?

Thanks!

Here’s a question to help you: What range of inputs do you think this would work for?

Also, a tip: If var result=1 is intended to be used only in factorialize, which seems to be the case, it should go inside the function. Maintaining those clean boundaries helps avoid bugs, helps others understand code and reflects clear thinking about where parts of your code belong.

2 Likes

Thank you very much! I was able to resolve the challenge with your advise! :slight_smile:

I had the same issue and solved it right away with that tip. Thanks!

1 Like