Factorialize a Number - Basic Algorithm Scripting - Free Code Camp

preview_player
Показать описание
In this basic algorithm scripting tutorial we factorialize a number. This is another tutorial that makes up a series where I cover the FreeCodeCamp curriculum. Enjoy!
Рекомендации по теме
Комментарии
Автор

Amazing is very easy to understand once you break it down step by step. Thank you for taking the time to explain it really makes a huge difference.

cosmelvillalobos
Автор

A little tricky but its making sense Mr. Ian so thanks again for your teachings
function factorialize(num) {
let result = 1;

while (num > 0) {
result *= num;
num -= 1;
}
return result;
}
console.log(factorialize(5));

zken
Автор

Great solution! Your code looks super clean by the way. Here's mine:
function factorialize(num) {
if (num < 0) {
return "Negative integers cannot be factorialized!!!";
} else if (num === 0) {
return 1;
} else {
return num * factorialize(num - 1);
}
}

ahmetmeliksahakdeniz
Автор

Thank you! Another splendid work of yours!

astratow
Автор

Thanks for this, I was trying to create a for loop, but it kept telling me that " i is not defined", the only difference here is that I did not include the "let result" variable :) Thanks again!

troyhackney
Автор

const reverseString =(str) =>

also we can improve your's first solution with arrow function to make it all in one clear string of code :)

georgylistopad
Автор

you made it clearer but its still difficult for me to understand

nnourrrrr
Автор

function factorialize(num) {
if(num==0) return 1
return num*factorialize(num-1)
}

rabih
Автор

I got the while loop pretty straight with how it runs through the code but can’t seem to understand the for loop like I don’t understand how it runs through the code.

paulfanning
Автор

Sheesh. And here I was trying to get a for loop to create an array of numbers between 1 and 'num', converting them to a string, then trying to .join() them with '*' and removing the ', '. Not worth xD

JonathanWrightZA
Автор

didn't understood a thing. copypasta'ed.

--Dipanshu--
visit shbcf.ru