Bonfire: Factorialize a Number Basic Algorithm Scripting JavaScript FreeCodeCamp.com

preview_player
Показать описание

Fan funding goes towards buying the equipment necessary to deliver 4k videos, 4k webcam, and a high quality microphone better audio. Any support is very appreciated!

My channel is here for aspiring programmers to learn easier and help debug any issues from the many great free resources available on the web.

Check out my other videos going over HTML, CSS, Ruby, Ruby on Rails, Java, JavaScript, Python, PHP, SQL, Command Line, BootStrap, jQuery, and WordPress from CodeCademy, CodeCombat, FreeCodecamp and more!

-~-~~-~~~-~~-~-
Please watch: "How I Became a Developer | My Developer Journey of the Last 3 Years | Ask a Dev"
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

Thank you Dylan, your videos are so helpful... these bonfires are tough. What I found helps me when I get stuck is to step away from freeCodeCamp for a day and watch full tutorials on Javascript...learning a few parts of the language at a time, such as (fun Functions, introduction to Arrays, what are Algorithms, Global vs Local and so forth). That's what works for me, some may find that other ways of learning works for them. As always I come to your channel on the daily... greatly appreciate all your hard work! ; )

roxyesquivel
Автор

Wow!! The way you guys did it made this seem so simple. I feel like I did this in the most complicated way possible lol.

Here's how I did it:
var num1;
var num2;
function factorialize(num) {
var arr = [];
var total = 0;
for(i=1; i<=num; i++){
arr.push(i);
}
if(num>0){
total = arr.reduce( (num1, num2) => num1 * num2 );
return total;
}
else
return 1;
}

factorialize(5);

reset
Автор

Thank you for posting this! Do you have any advice for practicing the right way to think when solving the bonfires. I understand everything that you are posting, and I understand how it works. However, what concerns me is that I wasn't able to solve it myself. My goal in free code camp is to not just get through it, but come to conclusions myself, so that I feel confident in real work situations. What is your thought process when solving these puzzles?

MrDpagillo
Автор

Another way to do it:


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

factorialize(5);

mirceaalexandruticovschi
Автор

This is so helpful thanks, but I am in FreeCodeCamp and I am learning the code no problem but when it comes to coded word problems and now the basic Algorithms my mind goes gets a little confused and frustrated on what to do and what functions I suppose to implement in the problems to solve them. So do you have any suggestions on how to overcome this hurdle because I need to understand these questions and problems better so that I can answer them.

frederickwilliams
Автор

Like Jeff & Dylan, I can't do the bonfires on my own. Googling is almost worse because StackOverflow, W3C schools, are hard to understand. I guess I'm just emoting here. I'd really like to say ...

Thanks for the tutorials! It gives me a way to think about the bonfires, and eventually I'll be able to find my own solutions.

mollyeichar
Автор

can you please explain you should we use `var count` instead of just using the `num` directly ?

moolipit
Автор

So in line 2 you define count to be equal to the number you are going to factorialize right? In line 9, within the loop you use num again to do the calculations. What I don't get is how this "num" starts out as a value of 1 in the beginning of the loop sequence. Where is that defined to be 1 ? Only i is defined as 1.

janverhulst
Автор

A much simpler and shorter solution:

function factorialize(num) {
var count = 1;
for (i = 1; i <= num; i++) {
count *= i;
}

return count;
}

tabacarumihai
Автор

Hey coding360 thanks for this what I want clarified though the reason you are using the variable count is it so that the value doesn't constantly change as apposed to using num. how come the count isn't changing in the loop just like it would change the num variable.

chriskissoon
Автор

My solution:
function factorialize(num) {

var answer = 1;
var count = num;
for(var i =1; i <= count; i++ ){
answer *=i;

}
return answer;
}

factorialize(5);

thegameguy
Автор

My Solution...

function factorialize(num) {

var i = 0;
var number = 1;

while (i < num) {
number *= i + 1;
i++;
}

return number;

}

ghostnote
Автор

function factorialize(x) {return x==0?1:x*factorialize(x-1)}

VKBteamkiller
Автор

You seem new to this. Not very well explained but I guess u got the job done right? I would have done this a little different and saved time...

function factorialize(num) {

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

factorialize(5);

BryanReese
visit shbcf.ru