Saturday, May 8, 2021

Node js slip2

 

Q.1  Create a Node.js Application that uses user defined Module to return the factorial of given number.

//create two files first file name fact.js and second file name Node.js

fact.js

function fact(n){
var f=1;
for(i=1;i<=n;i++)
{
   f=f*i;
};
return f;
};
module.exports=fact;

Node1.js
var fact=require("./fact.js");
console.log("Factorial of a number : ",fact(5));

Output
C:\Users\NEW\nodex>node Node1.js
Factorial of a number :  120

No comments:

Post a Comment

Slip 10. Write a jQuery code to make first word of each statement to bold.

  Slip 10. Write a jQuery code to make first word of each statement to bold.  <!DOCTYPE html> <html>   <head>     <scri...