MERN
#pass or fail
function cr(marks,callback)
{
console.log("Calculatinggg....")
if(marks>=35)
{
callback("Passed",marks);
}
else {
callback("Failed",marks);
}
}
function dr(results,marks)
{
console.log ("you
are",results,"with",marks);
}
cr(45,dr);
cr(20,dr);
#PIZZA PROGRAM
const
EventEmitter=require('node:events');
const emitter=new EventEmitter();
emitter.on("order_pizza",(size,top)=>
{console.log("order recieved
for a",size,"with ",top);
});
emitter.on("order_pizza",(size)=>{
if(size=='large'){
console.log("Serving a compliment
drink");
}});
emitter.emit("order_pizza","small","cheese");
emitter.emit("order_pizza","large","peperoni");
#RCB PROGRAM
class RCB
{
constructor(tname,cname,slogan)
{
this.tname=tname
;
this.cname=cname;
this.slogan=slogan;
}
Details()
{
console.log("Team name
is",this.tname);
console.log("Captain name
is",this.cname);
}
Slogan()
{
console.log("Slogan
is",this.slogan);
}
greet()
{
console.log("hii
captain",this.cname,"lead ",this.tname,"to
victory!!!");
}
}
const team= new RCB("Royal challengers
Bengaluru","Rajat patidar","Ee sala cup namdee!!!");
team.Details();
team.Slogan();
team.greet();
#Arithmetic
function calculate(a, b,
callback) {
console.log("Calculating...");
callback(a, b);
}
function add(x, y) {
console.log("Addition:", x + y);
}
function sub(x, y) {
console.log("Subtraction:", x - y);
}
function mul(x, y) {
console.log("Multiplication:", x * y);
}
function div(x, y) {
console.log("Division:", x / y);
}
calculate(7, 3, add);
calculate(7, 3, mul);
calculate(7, 3, sub);
calculate(7, 3, div);
#Counter.js #Functional component
import React, { useState } from
"react";
function Counter() {
const [count, setCount] = useState(0);
const increment = () => {
setCount(count + 1);
};
return (
<div>
<h2>Functional Counter:
{count}</h2>
<button
onClick={increment}>Increment</button>
</div>);}
export default Counter;
#App.js
import React from
"react";
import Counter from './Counter';
function App() {
return <Counter />;}
export default App;
#Counter.js #Class component
import React, { Component } from
"react";
class Counter extends Component {
state = { count: 0 };
increment = () => {
this.setState({ count: this.state.count + 1
});
};
render() {
return (
<div>
<h2>Class Counter:
{this.state.count}</h2>
<button
onClick={this.increment}>Increment</button>
</div>
); }}
export default Counter;
#App.js
import React from
"react";
import Counter from './Counter';
function App() {
return <Counter />;
}
export default App;
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("Alive",
"karthi", "2025");
const book2 = new Book("Last
Day", "love me", "2025");
console.log("book1
details:");
book1.getdetails();
console.log("book2
details:");
book2.getdetails();
cd C:\Users\karthik\Desktop\KARTHIK.S
npm init -y
npm install react react-dom
npx create-react-app counter-app
cd counter-app
npm start
Comments
Post a Comment