<div class="menu">
<span>item1</span>
<span>item2</span>
<span>item3</span>
</div>
document.querySelector(".menu").onclick = (ev) => {
let elem = ev.target;
if (elem.innerText == "item1") {
alert(1);
} else if (elem.innerText == "item2") {
alert(2);
} else if (elem.innerText == "item3") {
alert(3);
}
}
async function getResponse() {
let response = await fetch('https://dummyjson.com/products')
let jsonList = await response.json()
let list = document.querySelector('.products')
let key
let elements = jsonList.products
elements = elements.splice(0, 3)
for (key of elements) {
list.innerHTML +=
`<li class="item">
<h5 class="small_panel">${key.title}</h5>
<div class="full_panel">
<img src="${key.thumbnail}" alt="${key.description}"></img>
<p>brand: ${key.brand}</p>
<p>category: ${key.category}</p>
<p>${key.description}</p>
<p>discount percentage: ${key.discountPercentage} %</p>
<p>price: ${key.price} usd</p>
<p>rating: ${key.rating}</p>
<p>stock: ${key.stock}</p>
</div>
</li>`
}
}
getResponse()
const express = require('express');
const app = express();
exports.app = app;
const http = require('http');
const server = http.createServer(app);
app.get("/hello", (req, res) => {
//либо перенапрвление на сайт:
res.redirect("https://....");
//либо отдать свою страницу(файл):
res.sendFile(__dirname + '/public/index.html');
//или отправить напрямую html-код:
res.send(`
<html>
<head>
<title>Server</title>
</head>
<body>
<h1>hello server</h1>
</body>
</html>
`);
})
server.listen(8080, () => {
//console.log("\x1B[32m%c started", 'color: pink; background: red;');
});
const { Server } = require('http');
const s = Server();
s.addListener('request', function (req, res) {
res.end('My first server!\n');
});
s.listen(4321);
function alert(text) {
let divAlert = document.createElement("div");
divAlert.className = "my_alert";
divAlert.innerHTML = `Потдвердите действие:<br>${text}<br><button id="yes">OK</button>`;
document.body.appendChild(divAlert);
document.querySelector("#yes").onclick = () => {
divAlert.remove();
}
}
alert("hello");
alert = (...args) => {
console.log(...args[0]);
}