-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegacy.txt
111 lines (90 loc) · 3.54 KB
/
legacy.txt
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
API used: https://pokeapi.co/docs/v2
Tutorial: https://www.youtube.com/watch?v=zOrejGF0oBA
Enter Key function: https://github.com/DenverCoder1/weather-app-tutorial/blob/main/script.js
w/ Button only && w/ BG Color based on type
const getPokemon = document.querySelector(".getPokemon")
.addEventListener("click", () => {
// w/ Id Search
let pokemonId = document.getElementById("pokemonId").value
let urlPokemonId = `https://pokeapi.co/api/v2/pokemon/${pokemonId}`
// w/ Name Search
let pokemonName = document.getElementById("pokemonName").value.toLowerCase()
let urlPokemonName = `https://pokeapi.co/api/v2/pokemon/${pokemonName}`
fetch(urlPokemonName)
.then((res) => res.json())
.then((pokemon) => {
console.log(pokemon);
let pokemonResult = ''
pokemonResult += `
<center>
<ul>
<img src="${pokemon.sprites.front_default}" alt="pokemon">
<li>ID: ${pokemon.id}</li>
<li>NAME: ${pokemon.name}</li>
<li>ORDER: ${pokemon.order}</li>
<li>WEIGHT: ${pokemon.weight}</li>
</ul>
</center>
`
document.querySelector(".pokemonDiv")
.insertAdjacentHTML("afterbegin", pokemonResult)
})
})
Replaced with Switch Statements:
if(type == "???"){
document.querySelector(".pokemonList").style.backgroundColor = "#68A090"
}
else if (type == "normal"){
document.querySelector(".pokemonList").style.backgroundColor = "#68A090"
}
else if (type == "fire"){
document.querySelector(".pokemonList").style.backgroundColor = "#F08030"
}
else if (type == "fighting"){
document.querySelector(".pokemonList").style.backgroundColor = "#C03028"
}
else if (type == "water"){
document.querySelector(".pokemonList").style.backgroundColor = "#6890F0"
}
else if (type == "flying"){
document.querySelector(".pokemonList").style.backgroundColor = "#A890F0"
}
else if (type == "grass"){
document.querySelector(".pokemonList").style.backgroundColor = "#78C850"
}
else if (type == "poison"){
document.querySelector(".pokemonList").style.backgroundColor = "#A040A0"
}
else if (type == "electric"){
document.querySelector(".pokemonList").style.backgroundColor = "#F8D030"
}
else if (type == "ground"){
document.querySelector(".pokemonList").style.backgroundColor = "#E0C068"
}
else if (type == "psychic"){
document.querySelector(".pokemonList").style.backgroundColor = "#F85888"
}
else if (type == "rock"){
document.querySelector(".pokemonList").style.backgroundColor = "#B8A038"
}
else if (type == "ice"){
document.querySelector(".pokemonList").style.backgroundColor = "#98D8D8"
}
else if (type == "bug"){
document.querySelector(".pokemonList").style.backgroundColor = "#A8B820"
}
else if (type == "dragon"){
document.querySelector(".pokemonList").style.backgroundColor = "#7038F8"
}
else if (type == "ghost"){
document.querySelector(".pokemonList").style.backgroundColor = "#705898"
}
else if (type == "dark"){
document.querySelector(".pokemonList").style.backgroundColor = "#705848"
}
else if (type == "steel"){
document.querySelector(".pokemonList").style.backgroundColor = "#B8B8D0"
}
else if (type == "fairy"){
document.querySelector(".pokemonList").style.backgroundColor = "#EE99AC"
}