-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
35 lines (30 loc) · 1 KB
/
App.js
File metadata and controls
35 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
document.querySelector("#search"),addEventListener("click" ,getPokemon);
function lowerCaseName(string) {
return string.toLowerCase();
}
function getPokemon(e){
const name = document.querySelector("#pokemonName").value;
const pokemonName = lowerCaseName(name);
fetch(`https://pokeapi.co/api/v2/pokemon/${pokemonName}`)
.then((response) => response.json())
.then((data) => {
document.querySelector(".pokemonBox").innerHTML=`
<div class="imgjpg">
<img class="sugar"
src="${data.sprites.other.dream_world.front_default}"
alt="${data.name}"
</div>
<div class="pokemonInfo">
<h1 class="Heading">${data.name}</h1>
<p class="Weight">Weight : ${data.weight}</p>
<p class="Height">Height : ${data.height}</p>
<p class="Type">Type : ${data.types[0].type.name}</p>
<p class="Ability">Ability : ${data.abilities[0].ability.name}
</div>
`;
}).catch((err) => {
console.log('Pokemon not found' ,err);
});
e.preventDefault();
}
getPokemon();