Frontend/24_11_11_doga/Feladat1.js
2024-11-11 13:03:22 +01:00

38 lines
954 B
JavaScript

let url = "https://jsonplaceholder.typicode.com/posts/1/comments";
async function adatlekeres(url) {
try{
let response = await fetch(url);
if(!response.ok){
throw new Error("HIBA, a response nem OK");
} else{
let data = await response.json();
return data;
}
} catch{
console.log("Hiba történt!");
}
}
function createDomElement(element) {
let line = document.createElement("div");
line.innerHTML = `ID: ${element.id}, Email: ${element.email}`;
eredmeny.appendChild(line);
}
async function selectSpecifiedData(dataset){
dataset.forEach(element => {
if (element.id == 1 || element.id == 3 || element.id == 5){
createDomElement(element);
}
});
}
let eredmeny = document.getElementById("eredmeny");
async function main(){
let adatok = await adatlekeres(url);
await selectSpecifiedData(adatok);
}
main();