-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (26 loc) · 903 Bytes
/
index.js
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
let pokemonIndex = Math.floor(Math.random() * 151)
function increaseClickEvent(){
console.log("We are increasing!");
pokemonIndex++;
getPokemon(pokemonIndex);
}
function decreaseClickEvent(){
console.log("We are decreasing!");
pokemonIndex--;
getPokemon(pokemonIndex);
}
console.log("Index js loaded! ", document)
function getPokemon(pokemonIndex){
fetch(`https://pokeapi.co/api/v2/pokemon/${pokemonIndex}`)
.then(response => response.json())
.then(pokemon => {
updateDisplay(pokemon);
console.log(pokemon.name)
})
}
function updateDisplay(pokemon){
let NameElement = document.querySelector('.poke-header')
NameElement.innerHTML = pokemon.name
let imageContainer = document.querySelector('.image-container');
imageContainer.innerHTML = `<img width="300px" src="${pokemon.sprites.front_default}" ><img/>`
}