-
Notifications
You must be signed in to change notification settings - Fork 0
/
poke-api.js
111 lines (79 loc) · 3.9 KB
/
poke-api.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import axios from "axios";
import getClickedPokemon from "./clickedPokemon.js";
import {storedPokemon, displayPokemon} from "./savedPokemon.js";
import { getTime } from "./timer.js";
const getPokemon = async() => {
let pokemonNames = [];
// let pokemonLength = localStorage.getItem('pokemonList')? JSON.parse(localStorage.getItem('pokemonList')).length
// : null
// console.log(pokemonLength)
let pokemonID = JSON.parse(localStorage.getItem('pokemonList'));
// console.log(pokemonID)
// console.log(pokemonID[0]['pokemon-id'])
// console.log(!localStorage.getItem('pokemonList'))
// console.log(typeof pokemonLength !== 'number')
// console.log(pokemonLength < 6)
// || (typeof pokemonLength !== 'number' || pokemonLength < 6)
if(!localStorage.getItem('pokemonList')){
for(let i = 1; i <= 12; i++ ){
// let testingNum = i - 1
// debugger
// console.log('keeping track of the i num: ', i)
// console.log(testingNum)
// // console.log('tracking number', pokemonID[testingNum]['pokemon-id'], 'and i number: ', i)
// console.log(pokemonID.includes(pokemonID[0]['pokemon-id']))
// let getTrue;
// let convertToArr = Object.entries(pokemonID)
// console.log(convertToArr)
// let hardCodedArr = Object.entries(convertToArr[0][1])
// console.log(convertToArr[testingNum][i])
// console.log(hardCodedArr)
// console.log(convertToArr.includes(convertToArr[testingNum][i]))
// if(typeof pokemonID[testingNum]['pokemon-id'] === undefined || pokemonID[testingNum]['pokemon-id'] === undefined){
// getTrue = false;
// }else {
// getTrue = pokemonID[testingNum]['pokemon-id'] !== undefined && pokemonID[testingNum]['pokemon-id'] === i? true : false
// }
// console.log(getTrue)
// if(getTrue){
// if(localStorage.getItem('pokemonList') !== null && pokemonID[testingNum]['pokemon-id'] === i){
// continue;
// }
// }
const randomPokemon = Math.floor(Math.random() * 350)
const response = await axios.get(`https://pokeapi.co/api/v2/pokemon/${randomPokemon}`)
let pokemonName = await response.data.name;
let pokemonImages = await response.data.sprites;
let keepCount = 0;
let showPokeImg = document.createElement('img');
showPokeImg.setAttribute('class', 'pokeball-img')
showPokeImg.src = './images/pokeball.png'
let childContainer = document.createElement('div');
childContainer.setAttribute('class', 'poke-component')
childContainer.setAttribute('id', `pokemon-id-${i}`)
childContainer.append(showPokeImg);
let parentContainer = document.querySelector('#app')
parentContainer.append(childContainer)
pokemonNames.push({pokemonName, pokemonImages});
let clickPokemon = document.querySelector(`#pokemon-id-${i}`);
clickPokemon.addEventListener('click', (e) => {
keepCount++
// console.log(e)
// console.log(e.pointerType)
// console.log(e.type)
if(e.pointerType && e.type && keepCount > 1){
// console.log('this works')
// console.log('keeping count: ', keepCount)
return
}
getClickedPokemon(keepCount, i, showPokeImg, childContainer, pokemonName, pokemonImages)
storedPokemon(keepCount, i, showPokeImg, childContainer, pokemonName, pokemonImages)
}
)
// displayPokemon()
}
}
displayPokemon()
return pokemonNames
}
export default getPokemon;