How To Write A Programm That Will Accept Any Positive Integer

Discussion in 'JavaScript' started by kingsley, Nov 5, 2007.

  1. #1
    Please i want to know how to write a programm that will accept any positive integer from the keyboard and display and compute its factorial

    Thank you.
    Kingsley
     
    kingsley, Nov 5, 2007 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here's the function.. it's up to you to implement it

    
    function fact(n)
    {
      if (n == 1 || n == 0)
      { return 1; }
      else 
      {return n * fact(n-1); }
    }
    
    Code (markup):
    i didn't check that anywhere but it should work... i hope i'm not doing your homework for you
     
    Jamie18, Nov 5, 2007 IP