Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 07 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:33
    User @bjorno43 unbanned @linkin-park
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 25 2019 17:12
    @mstellaluna banned @cmal
  • Apr 01 2019 18:11
    thecodingaviator labeled #31179
  • Apr 01 2019 18:11
    thecodingaviator labeled #31179
  • Apr 01 2019 18:09
    thecodingaviator commented #31179
  • Apr 01 2019 18:09
    thecodingaviator labeled #31182
  • Apr 01 2019 18:09
    thecodingaviator labeled #31182
  • Apr 01 2019 18:07
    thecodingaviator commented #31182
  • Apr 01 2019 18:07
    thecodingaviator labeled #31190
  • Apr 01 2019 18:07
    thecodingaviator labeled #31190
  • Apr 01 2019 18:07
    thecodingaviator commented #31190
  • Apr 01 2019 18:05
    thecodingaviator commented #31157
  • Apr 01 2019 18:04

    thecodingaviator on master

    remove A (#31157) (compare)

  • Apr 01 2019 18:04
    thecodingaviator closed #31157
  • Apr 01 2019 18:04
    thecodingaviator closed #33788
  • Apr 01 2019 18:04
    thecodingaviator commented #33788
  • Apr 01 2019 18:02
    thecodingaviator closed #31059
Ahmed Ramy
@Shadilix
like in a for loop
for ( var i ; ?? <= num ; i--)
am stuck with this one so thats why i tried the other way around which is a definite infinite loop
Nick Cleary
@Hijerboa
quick question: is there a way to use .replace() in order to replace any non-alphanumberic character with null, or must I use .replace() for each and every one seperately?
Manish Giri
@Manish-Giri
@Hijerboa you can use a regex
kumquatfelafel
@kumquatfelafel
@Shadilix
With regards to starting point: Say we're doing 5!. What is num?
With regards to condition (when to stop): For the factorial of anything, do we multiply by 0? How about 1?
Nick Cleary
@Hijerboa
@Manish-Giri ok thank you
CamperBot
@camperbot
hijerboa sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6136 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ahmed Ramy
@Shadilix
num is the number we want to factoralize in case of 5! , num = 5
and no we dont multiply any factorial by 0 but 1 is viable but expendable
kumquatfelafel
@kumquatfelafel

1 is viable but expendable

good. Not everyone might catch that ;)

@Shadilix So if we're starting at end and working backwards, could num give us our starting point?
Joseph
@revisualize
Hey hey.
Ahmed Ramy
@Shadilix
thanks :D
i am trying something , will show u in a bit
kumquatfelafel
@kumquatfelafel
hi
Ahmed Ramy
@Shadilix
function factorialize(num) {
  if (num === 0)
    {
      return 1;
    }
  for (var i = num ; i >=2 ; i--)
    {
      num *= i;
    }
}
ohh that also didnt work
kumquatfelafel
@kumquatfelafel
@Shadilix
1.where's your return?
2.what happens when num = 1?
Joseph
@revisualize
@Shadilix You know.. It's actually better to count up than to count down.
Saif Ur Rahman
@saifsmailbox98
@Shadilix you are not returning after the for loop and you can put the for loop inside an else.
Joseph
@revisualize
@Shadilix If you count down you could end up with a problem where you break below the loop.
@Shadilix You also don't have a return statement for your function.
@Shadilix You have one if the value of num is 0. But, you don't have one for anything else.
Ahmed Ramy
@Shadilix
opps yea i forgot the return
but when i used the counting "up" ... i ended up with an infinite loop
Stephen James
@sjames1958gm
@Shadilix And you are multiplying by num twice
@Shadilix Did you grow num and try to stop at num?
Ahmed Ramy
@Shadilix
@Shadilix Did you grow num and try to stop at num?
what ? XD
Saif Ur Rahman
@saifsmailbox98
@Shadilix you are also multiplying num with num in the first run
Stephen James
@sjames1958gm
@sjames1958gm i < num while also doing num *= i
kumquatfelafel
@kumquatfelafel
@Shadilix he means, did you have something like i <= num or whatever... which you had
Ahmed Ramy
@Shadilix
um shouldnt that code be like
num = 5
then
i = 5
then what happens in the loop is
543*2?
Saif Ur Rahman
@saifsmailbox98
5 * 5 * 4 * 3 * 2
kumquatfelafel
@kumquatfelafel
@Shadilix num is already 5, so this happens ^^^
Ahmed Ramy
@Shadilix
function factorialize(num) {
  if (num === 0)
    {
      return 1;
    }
  for (var i = num -1 ; i >=2 ; i--)
    {
      num *= i;
    }
  return num;
}

factorialize(1);
that worked ! :D
Stephen James
@sjames1958gm
@Shadilix :+1:
Saif Ur Rahman
@saifsmailbox98
:+1:
Ahmed Ramy
@Shadilix
thanks !!!!
@saifsmailbox98 @saifsmailbox98 @kumquatfelafel
CamperBot
@camperbot
shadilix sends brownie points to @saifsmailbox98 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 375 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 636 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
kumquatfelafel
@kumquatfelafel
@Shadilix what you can also do is create another variable to store the product. That way, you can go up or down with ease without modifying num.
Ahmed Ramy
@Shadilix
how so ?
@sjames1958gm thanks !
CamperBot
@camperbot
shadilix sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7935 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
@Shadilix you'd just have something like...
function factorialize(num) {
  var factorial =1;
  for (var i = 2; i <= num ; i++)
  {
      factorial *= i;
  }
  return factorial;
}
Ahmed Ramy
@Shadilix
oh , i tried that but for some reason it didnt work ...
hold on i'll try it again before going for the next challenge
Roxroy
@roxroy
@kysnazz , you can round the number to 2 decimal places
console.log( ( 0.6*6).toFixed(2) ) // OutPut 3.60