Mern.
batman.js
class Batman {
#realname = "Bruce Wayne";
getsuperheroname() {
return "This is batman";
}
getidentity() {
}
return "My secret identity is " + this.#realname;
}
module.exports = Batman;
super.js
class Superman {
#realname = "Clark Kent";
getsuperheroname() {
return "This is superman";
}
getidentity() {
return "My secret identity is " + this.#realname;
}
}
module.exports = Superman;
main.js
const BatmanClass = require("./batman.js");
const SupermanClass = require("./super.js");
const Batman = new BatmanClass();
const Superman = new SupermanClass();
console.log(Batman.getsuperheroname());
console.log(Batman.getidentity());
console.log(Superman.getsuperheroname());
console.log(Superman.getidentity());
pass.js
function CR(Marks, callback) {
console.log("checking result");
if (Marks >= 35) {
callback("passed");
} else {
callback("failed");
}
}
function DR(result) {
console.log("You have " + result);
}
CR(45, DR);
CR(30, DR);
pizza.js
const EventEmitter = require("node:events");
const emitter = new EventEmitter();
emitter.on("order_pizza", (size, topping) => {
console.log(`Order received! Baking a ${size} pizza with ${topping}`);
if (size === "large") {
console.log("Serving a complimentary drink");
}
});
emitter.emit("order_pizza", "medium", "mushroom");
emitter.emit("order_pizza", "large", "margherita");
show_status.js
function showstatus(msg, callback) {
console.log("status:" + msg);
callback();
function NextAct() {
console.log("Next Msg");
}
}
showstatus("loading completed:", NextAct);
showstatus("User authentication", NextAct);
RCB program
class RCB {
constructor(teamName, captainName, slogan) {
this.teamName = teamName;
this.captainName = captainName;
this.slogan = slogan;
}
displayDetails() {
console.log("Team Name:", this.teamName);
console.log("Captain Name:", this.captainName);
}
printSlogan() {
console.log(`Slogan: ${this.slogan}!`);
}
greetCaptain() {
console.log(`Hello Captain ${this.captainName}, lead ${this.teamName} to victory!`);
}
}
const rcbTeam = new RCB("Royal Challengers Bangalore", "Rajat Patidar", "Play Bold");
rcbTeam.displayDetails();
rcbTeam.printSlogan();
rcbTeam.greetCaptain();
Author program
function Book(title, author, year) {
this.title = title;
this.author = author;
this.year = year;
this.getDetails = function() {
console.log("Title: " + this.title);
console.log("Author: " + this.author);
console.log("Year: " + this.year);
};
}
const book1 = new Book("Alice", "Cho", "2025");
const book2 = new Book("Last Day", "Gagan", "2025");
console.log("Book 1 Details:");
book1.getDetails();
console.log("Book 2 Details:");
book2.getDetails();
Comments
Post a Comment