I am new to Javascript and am following freecodecamp. As I understand, I think I should be able to multiply a number by i each time it changes in a for loop by the value of i itself. I am doing this because I am trying to factorialize. I sort of peeped at the answer and they used a factorialize type javascript function or something. I'd still like to solve this using my own coding. How would I do this?
Below is the code of what I have already tried.
function factorialize(num) {
for (let i = 1; i < num; i++) {
let answer = i * num;
}
return answer;
}
If I input 10 for a number I'd like it to take the factorial of 10 (i.e 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1). I would hope this to work for 0 as well somehow, but we can always start with my original question.