I'M_DEVELOPERπŸ‘¨β€πŸ’»
15 subscribers
12 photos
3 videos
1 link
HELLOπŸ™‹β€β™‚οΈ , Welcome to my channel πŸ’«
I AM BACKEND NODE JS DEVELOPER πŸ‘¨β€πŸ’»
Download Telegram
πŸ’―1
const computer = {
model: "Asus Tuf Gaming A15",
price: "830$",
count: 3,
};
function getInfo(computer) {
return computer;
}
const s = getInfo(computer);
console.log(s);
// 2-usul
function Computer(model, price, count) {
this.model = model;
this.price = price;
this.count = count;
this.getInfo = function () {
return `Model: ${this.model} , Price: ${price} , Count: ${count}`;
};
}
const Asus = new Computer("Hp i513", "550$", 3);
console.log(Asus.getInfo());
function Checkinteger(number) {
return number;
}
console.log(Number.isInteger(Checkinteger(5)));
console.log(Number.isInteger(Checkinteger(5.5)));
function ChangeText(text, target, replacement) {
return text.split(target).join(replacement); // split qirqish join qo'shish
}
const natija = ChangeText("Assalomu alaykum", "al", "ok");
console.log(natija);
function calculateArea(yuza) {
const area = this.length * this.width;
return yuza + " " + area;
}
const rectangle1 = { length: 5, width: 10 };
const rectangle2 = { length: 7, width: 3 };
const r = calculateArea.call(rectangle1, "yuza");
console.log(r);
function calculateArea(yuza) {
const area = this.length * this.width;
return yuza + " " + area;
}
const rectangle1 = { length: 5, width: 10 };
const rectangle2 = { length: 7, width: 3 };
const r = calculateArea.apply(rectangle1, ["yuza"]);
console.log(r);
function calculateArea(yuza) {
const area = this.length * this.width;
return yuza + " " + area;
}
const rectangle1 = { length: 5, width: 10 };
const rectangle2 = { length: 7, width: 3 };
const r = calculateArea.bind(rectangle1);
console.log(r("yuza"));
function SplitText(text, split) {
return text.split(split);
}
const natija = SplitText("Learning JavaScript is fun!", " ");
console.log(natija);
// 1
let mevalar = ["olma", "banan"];
mevalar.push("apelsin");
console.log(mevalar);
// 2
let ranglar = ["qizil", "yashil", "ko'k"];
let oxirgiRang = ranglar.pop();
console.log(oxirgiRang);
console.log(ranglar);
// 3
let avtomobillar = ["BMW", "Audi", "Mercedes"];
let birinchiAvto = avtomobillar.shift();
console.log(birinchiAvto); // "BMW"
console.log(avtomobillar);
// 4
let shaharlar = ["Toshkent", "Samarqand"];
let qishloqlar = ["Chirchiq", "Angren"];
let barchaJoylar = shaharlar.concat(qishloqlar);
console.log(barchaJoylar);
// 5
let yoshlar = [15, 18, 22, 17, 19];
let kattaYoshlar = yoshlar.filter((yosh) => yosh >= 18);
console.log(kattaYoshlar);
// 6
let sonlar = [2, 4, 6];
let kvadratlar = sonlar.map((son) => son * son);
console.log(kvadratlar);
// 1
let text2 = "Salom, Dunyo Salom";
console.log(text2.indexOf("Dunyo"));
console.log(text2.indexOf("Salom"));
console.log(text2.indexOf("Xayr")); // -1 (topilmasa -1 qaytaradi)
// 2
let text1 = "Salom, Dunyo Salom";
console.log(text1.lastIndexOf("Salom"));
console.log(text1.lastIndexOf("Dunyo"));
// 3
let text3 = "Salom, Dunyo";
console.log(text3.includes("Dunyo"));
console.log(text3.includes("Xayr"));
// 4
let text = "Salom, Dunyo Barcha";
let arr = text.split(", ");
console.log(arr);
// 5
let array = ["Salom", "Dunyo"];
console.log(array.join(" - "));
1πŸ‘1πŸ”₯1
Eski vazifalardan Takrorlash bo'ldi
πŸ‘¨β€πŸ’»2
This media is not supported in the widget
VIEW IN TELEGRAM
πŸ”₯4
function getHotelDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Adress:Toshkent shahar chilonzor tumani, Qavat: 7ta, xonalar soni: 60ta, bo'sh xonalar soni: 10ta "
);
}, 2000);
});
}
function getFlightDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Uchish joyi:Rossiya domodedevo Aeraporti, Uchish vaqti : 19:00 ,Yetib borish : 22:00 "
);
}, 2000);
});
}
function getWeatherDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Rosiyya Toshkent yo'nalishi bo'yicha ob-havo ma'lumoti : 3 soatli parvoz vaqtida yomg'ir yoki qor yo'q havo ozgina sovuqroq 2'C dan 5'C gacha haroratda bo'ladi ! "
);
}, 2000);
});
}
getHotelDetails().then((data) => {
console.log(data);
}),
(err) => {
console.log(err);
};
getFlightDetails().then((data) => {
console.log(data);
}),
(err) => {
console.log(err);
};
getWeatherDetails().then((data) => {
console.log(data);
}),
(err) => {
console.log(err);
};
πŸ‘Œ2πŸ‘1πŸ”₯1
vazifadan parcha
function getHotelDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Adress:Toshkent shahar chilonzor tumani, Qavat: 7ta, xonalar soni: 60ta, bo'sh xonalar soni: 10ta "
);
}, 2000);
});
}
function getFlightDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Uchish joyi:Rossiya domodedevo Aeraporti, Uchish vaqti : 19:00 ,Yetib borish : 22:00 "
);
}, 2000);
});
}
function getWeatherDetails() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
"Rosiyya Toshkent yo'nalishi bo'yicha ob-havo ma'lumoti : 3 soatli parvoz vaqtida yomg'ir yoki qor yo'q havo ozgina sovuqroq 2'C dan 5'C gacha haroratda bo'ladi ! "
);
}, 2000);
});
}
function bookTrip() {
Promise.all([getHotelDetails(), getFlightDetails(), getWeatherDetails()])
.then((data) => {
const [hotelData, flightData, weatherData] = data;
console.log("Mehmonxona ma'lumotlari olingan --->", hotelData);
console.log("Parvoz ma'lumotlari olingan --->", flightData);
console.log("Ob-havo ma'lumotlari olingan --->", weatherData);
})
.catch((error) => {
console.log("xato");
});
}
bookTrip();
πŸ”₯3πŸ‘Œ2πŸ‘1
const son = Math.trunc(Math.random() * 10);
const Mypromise = new Promise((yes, no) => {
setTimeout(() => {
if (son >= 5) {
yes(true);
} else {
no(false);
}
}, 3000);
});
Mypromise.then(
(data) => {
console.log(data);
},
(data) => {
console.log(data);
}
);
πŸ”₯3πŸ‘Œ2πŸ‘1
function makeReservation(xona) {
return new Promise((res, rej) => {
if (xona) {
res("Buyurtma muvaffaqiyatli !");
} else {
rej("Kechirasiz, xonalar mavjud emas !");
}
});
}
makeReservation(true) // Argument sifatida true yozilsa buyurtma tasdiqlandi false yozilsa rad etildi !
.then((data) => {
console.log(data);
return "tasdiqlandi !";
})
.catch((error) => {
console.log(error);
return "rad etildi";
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.log(error);
});
πŸ”₯4πŸ‘Œ2πŸ‘1
function makeReservation(xona) {
return new Promise((res, rej) => {
if (xona) {
res("Buyurtma tasdiqlandi!");
} else {
rej("Kechirasiz, xonalar mavjud emas !");
}
});
}
makeReservation(true) // Argument sifatida true yozilsa resolve false yozilsa reject ishlaydi !
.then((data) => {
console.log(data);
})
.catch((e) => {
console.log(e);
});
πŸ”₯4πŸ‘2πŸ‘Œ2
// 2-usul

const h1 = document.createElement("h1");
document.body.appendChild(h1);
function cars() {
const ul = document.createElement("ul");
const li = document.createElement("li");
const h3 = document.createElement("h3");
const p = document.createElement("p");
const image = document.createElement("img");
image.src =
"https://imgd.aeplcdn.com/370x208/n/cw/ec/144851/exter-exterior-right-front-three-quarter-29.jpeg?isig=0&q=80";
h1.innerHTML = "Auto Salon";
h3.innerHTML = "Title";
p.innerHTML =
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla, ex.";
document.body.appendChild(ul);
ul.appendChild(li);
li.appendChild(h3);
li.appendChild(p);
li.appendChild(image);
}
cars();
cars();
cars();
cars();
const h2 = document.createElement("h2");
h2.innerHTML = "About Us";
document.body.appendChild(h2);
function names() {
const section = document.createElement("section");
document.body.appendChild(section);
const image = document.createElement("img");
image.src =
"https://imgd.aeplcdn.com/370x208/n/cw/ec/144851/exter-exterior-right-front-three-quarter-29.jpeg?isig=0&q=80";
section.appendChild(image);
}
names(), names(), names(), names();
⚑4πŸ‘4πŸ‘Œ2
const url = require("node:url");
const uuid = require("uuid");
const http = require("node:http");

class ResponseData {
constructor(statusCode, message, data) {
this.statusCode = statusCode;
this.message = message;
this.data = data;
}
}

class Fruit {
constructor(name, price, count) {
this.id = uuid.v4();
this.name = name;
this.price = price;
this.count = count;
}
}

class Car {
constructor(model, price) {
this.id = uuid.v4();
this.model = model;
this.price = price;
}
}

const fruits = [];
const cars = [];

const server = http.createServer((req, res) => {
const [, moduleName, id] = url.parse(req.url).pathname.split("/");
const method = req.method;

if (method === "GET" && moduleName === "fruits" && !id) {
const response = new ResponseData(200, "Success", fruits);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
} else if (method === "GET" && moduleName === "cars" && !id) {
const response = new ResponseData(200, "Success", cars);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));

// get fruits
} else if (method === "GET" && moduleName === "fruits" && id) {
const fruit = fruits.find((f) => f.id === id);
if (!fruit) {
const response = new ResponseData(404, "Fruit not found");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
} else {
const response = new ResponseData(200, "Success", fruit);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
}

// get cars
} else if (method === "GET" && moduleName === "cars" && id) {
const car = cars.find((c) => c.id === id);
if (!car) {
const response = new ResponseData(404, "Car not found");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
} else {
const response = new ResponseData(200, "Success", car);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
}

//fruitlarni delete qilish
} else if (method === "DELETE" && moduleName === "fruits" && id) {
const fruitIndex = fruits.findIndex((el) => el.id === id);
if (fruitIndex === -1) {
const response = new ResponseData(404, "Fruit not found!");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
} else {
const deletedFruit = fruits.splice(fruitIndex, 1)[0];
const response = new ResponseData(200, "Fruit deleted", deletedFruit);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
}

//carlarni delete qilish
} else if (method === "DELETE" && moduleName === "cars" && id) {
const carIndex = cars.findIndex((el) => el.id === id);
if (carIndex === -1) {
const response = new ResponseData(404, "Car not found!");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
} else {
const deletedCar = cars.splice(carIndex, 1)[0];
const response = new ResponseData(200, "Car deleted", deletedCar);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
}
// fruis post
} else if (method === "POST" && moduleName === "fruits") {
let reqData = "";
req.on("data", (chunk) => {
reqData = reqData + chunk.toString();
});

req.on("end", () => {
let body = {};
if (reqData.length) {
body = JSON.parse(reqData);
}

// body name stringligini tekshirish
if (typeof body.name !== "string") {
const response = new ResponseData(400, "Name must be a string!");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
return;
}
πŸ”₯2πŸ‘2πŸ‘Œ1πŸ†’1


//body count numberligini tekshirish
if (typeof body.count !== "number" || typeof body.price !== "number") {
const response = new ResponseData(
400,
"Count and price must be numbers!"
);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
return;
}

const newFruit = new Fruit(body.name, body.price, body.count);
fruits.push(newFruit);

const response = new ResponseData(201, "Created", newFruit);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
});

// cars post
} else if (method === "POST" && moduleName === "cars") {
let reqData = "";
req.on("data", (chunk) => {
reqData = reqData + chunk.toString();
});

req.on("end", () => {
let body = {};
if (reqData.length) {
body = JSON.parse(reqData);
}

// car modelni stringligini tekshirish
if (typeof body.model !== "string") {
const response = new ResponseData(400, "Model must be a string!");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
return;
}

//cars price ni tekshirish
if (typeof body.price !== "number") {
const response = new ResponseData(400, "Price must be a number!");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
return;
}

//..............
const newCar = new Car(body.model, body.price);
cars.push(newCar);

const response = new ResponseData(201, "Created", newCar);
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
});
} else {
const response = new ResponseData(404, "Not Found");
res.writeHead(response.statusCode);
res.end(JSON.stringify(response));
}
});

server.listen(3000, () => {
console.log("Server is running at http://localhost:3000");
});
⚑2πŸ”₯1πŸ‘Œ1πŸ—Ώ1