Header Ads Widget

BCA Information

nodeslip2a

 Q.2.A.Create a Node.Js Application that uses user define Module to return the factorial of given number.

Slip2a.js

/factorial Using User Module with user input

var factorial = require('./fact.js');

var rl = require('readline').createInterface({

    input: process.stdin,

    output: process.stdout

  });


  rl.question('Enter The Number : ', x => {

    var ans=factorial(x);

    console.log(`Your Answer Is : ${ans}`);

    rl.close();

});


Fact.js

module.exports = function factorial(x) 


  if (x === 0)

 {

    return 1;

 }

  return x * factorial(x-1);

         

}


Post a Comment

1 Comments

Popular Posts

OOSE Notes
Data Mining And Data Science