From 1e8c903541da20d00b39f42e40a2f8a204411f9e Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Fri, 24 Apr 2026 11:32:50 +0200 Subject: [PATCH] pokebuilder --- 32_pokemon_team_builder/index.html | 19 +++++++++++ 32_pokemon_team_builder/script.js | 53 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 32_pokemon_team_builder/index.html create mode 100644 32_pokemon_team_builder/script.js diff --git a/32_pokemon_team_builder/index.html b/32_pokemon_team_builder/index.html new file mode 100644 index 0000000..d43ad6d --- /dev/null +++ b/32_pokemon_team_builder/index.html @@ -0,0 +1,19 @@ + + + + + + Poké-team builder + + +

Poké-team builder

+
+ + +
+ +
+ + + + \ No newline at end of file diff --git a/32_pokemon_team_builder/script.js b/32_pokemon_team_builder/script.js new file mode 100644 index 0000000..3f33d30 --- /dev/null +++ b/32_pokemon_team_builder/script.js @@ -0,0 +1,53 @@ +const tymDiv = document.getElementById("tym"); +const btnGeneruj = document.getElementById("btnGeneruj"); +const btnUloz = document.getElementById("btnUloz") + +let aktualniTym = []; + +async function nactiPokemona(id) { + const url = `https://pokeapi.co/api/v2/pokemon/${id}`; + const response = await fetch(url); + const data = response.json(); + return data +} +async function zobrazTym(seznamID) { + tymDiv.innerHTML = ""; + aktualniTym = seznamID; + for (const id of seznamID){ + const poke = await nactiPokemona(id); + const div = document.createElement("div"); + div.innerHTML= ` + ${poke.name} +

${poke.name}

+

ID: #${poke.id}

+
+ `; + tymDiv.appendChild(div); + } +} + +function vygenerujNahodnaID() { + let ids= []; + for (let i = 0; i<6;i++){ + const nahoda = Math.floor(Math.random()*151)+1; + ids.push(nahoda); + } + zobrazTym(ids); +} + +btnGeneruj.addEventListener("click",vygenerujNahodnaID) + +btnUloz.addEventListener("click",() => { + localStorage.setItem("moje_pokemony",JSON.stringify(aktualniTym)); + alert("Tým uložen do prohlížeče"); +}); + +function nactiUlozenyTym() { + const ulozeno = localStorage.getItem("moje_pokemony"); + if (ulozeno){ + zobrazTym(JSON.parse(ulozeno)); + } +} +nactiUlozenyTym(); \ No newline at end of file