const os = require ( 'os' ); const fs = require ( 'fs' ); const chalk = require ( 'chalk' ); //Install it 1st command is-- npm install chalk@4.1.2 //01 console . log ( 'Hello world' ); //02 console . log ( chalk . green ( 'Hello World' )); //03 var add = ( num1 , num2 ) => num1 + num2 ; console . log ( add ( 3 , 4 )); //04 os information console . log ( os . platform ()); console . log ( os . release ()); //05 file read (must have a txt file in same folder named text.txt) fs . readFile ( 'text.txt' , 'utf8' , ( err , data ) => { if ( err ) { console . error ( 'Error reading file:' , err ); return ; } console . log ( data ); }); //06 odd even with color function evenodd ( x ) { if ( x % 2 == 0 ) { console . log ( chalk . green ( "even" )) } else { console . log ( chalk . red ( "odd" )) } } evenodd ( 23 ) evenodd ( 24 ) //07 swap number let a = 5 ; let ...
Comments
Post a Comment