Assignment 01
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 b = 10;
let c = 15
console.log('Before swap:', a, b, c);
[a, b, c] = [b, c,a];
console.log('After swap:', a, b, c);
//08 1 to 10 number odd will be red even will be green
for (let i = 1; i <= 10; i++) {
if(i%2==0){
console.log(chalk.green(i))
}
else{
console.log(chalk.red(i))
}
}
Comments
Post a Comment