Factorialize a number help with 0 [SOLVED]

Factorialize a number help with 0 [SOLVED]


Hi all, just working on some of the algorithms for FCC.

I’m working on factorializing a number and I’m not sure how to get this code to work with the number 0.

The code is probably wonky, but I’m pretty happy that it works for all but one number.

Edit: Got it! Thanks Cowwy!


First off, divide by 0 is a no no. Okay in JavaScript as it will return infinity, but other languages will give you an divide by 0 warning.

result = num/num

It then jumps to the for loop which resets the result variable to 1;

To answer the question, you need some sort of decision making process when you encounter an input of 0 or 1; Something has to do with if statement. :slight_smile:

Does that give you enough hints?


Thanks! :slight_smile:

My original if statement wasn’t working

Edit: I fixed it! Thanks a bunch man


Nevermind! I got it and I am dumb :frowning:

Can’t use x = 0…