-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguts.js
211 lines (176 loc) · 5.72 KB
/
guts.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
const question1 = document.querySelector("#question1");
const question2 = document.querySelector("#question2");
const question3 = document.querySelector("#question3");
const question4 = document.querySelector("#question4");
const body = document.querySelector("body");
const optionsArray = [
"Alakazam",
"Arcanine",
"Bulbasaur",
"Cubone",
"Ditto",
"Gloom",
"Gyarados",
"Hitmonlee",
"Horsea",
"Koffing",
"Mewtwo",
"Pikachu",
"Seaking",
"Tauros",
"Venonat",
"Victreebe",
"eevee",
"Ivysaur",
"Venusaur",
"Charmander",
"Charmeleon",
"Charizard",
"Squirtle",
"Wartortle",
"Blastoise",
"Caterpie",
"Metapod",
"Butterfree",
"Weedle",
"Kakuna",
"Beedrill",
"Pidgey",
"Pidgeotto",
"Pidgeot",
"Rattata",
"Raticate",
"Spearow",
"Fearow",
"Ekans",
"Arbok",
];
// axios.get('https://pokeapi.co/api/v2/pokemon?limit=151')
// .then(function (response) {
// // handle success
// console.log(response);
let randomPokemon;
// getting game data
const container = document.querySelector('#pokemon-container');
const randomNum = function(){
return Number(Math.floor(Math.random() * 151));
// return Number(Math.floor(Math.random() * 151));
// console.log(ran);
}
const fPokeData = async function(){
const res = await axios.get('https://pokeapi.co/api/v2/pokemon?limit=151')
const pokemon = await res.data.results;
getPokeData(pokemon);
}
let gamedata;
const main = document.querySelector('main');
const playbtn = document.querySelector('#play');
// making a function where i can get random pokemon
const getPokeData = async function(pokemon){
let randomvar = randomNum();
// const pokemon = await fPokeData();
randomPokemon = pokemon[randomvar -1];
console.log(randomPokemon);
console.log(randomvar);
console.log(`https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${randomvar}.png`);
return newdata(randomvar);
};
async function newdata(randomvar) {
const newhtml = `
<img class=pokeIMGX src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${randomvar}.png"/>
`;
console.log(newhtml)
container.insertAdjacentHTML("beforeend",newhtml);
}
fPokeData();
//multiple choice btns
const playBtn = document.querySelector("#play-btn");
playBtn.addEventListener("click", function (){
playBtn.innerHTML = '';
const container = document.createElement("div");
container.setAttribute('class', 'container');
const question1 =document.createElement("button");
question1.setAttribute("class", "next-hide");
question1.textContent = optionsArray[Math.floor(Math.random() * optionsArray.length)]
question1.addEventListener("click", () =>{
question1.style.backgroundColor = 'red';
})
const question2 = document.createElement("button");
question2.setAttribute("class", "next-hide");
question2.textContent = randomPokemon.name;
question2.addEventListener("click", () =>{
question2.style.backgroundColor = 'green';
const pokeImageX = document.querySelectorAll('#pokeIMGX');
pokeImageX.innerHTML = "";
alert("Good Job!");
fPokeData();
getPokeData();
newdata();
question();
container.innerHTML = '';
})
const question3 = document.createElement("button");
question3.setAttribute("class", "next-hide");
question3.textContent = optionsArray[Math.floor(Math.random() * optionsArray.length)]
question3.addEventListener("click", () =>{
question3.style.backgroundColor = 'red';
})
const question4 = document.createElement("button");
question4.setAttribute("class", "next-hide");
question4.textContent = optionsArray[Math.floor(Math.random() * optionsArray.length)]
question4.addEventListener("click", () =>{
question4.style.backgroundColor = 'red';
})
container.append(question1);
container.append(question2);
container.append(question3);
container.append(question4);
body.append(container);
})
// for my not random but random pokemon in my questions
function randomValueGenerator(array) {
const randomIndex = Math.floor(Math.random() * array.length);
console.log(array[randomIndex]);
}
randomValueGenerator(optionsArray);
function question() {
randomValueGenerator(optionsArray);
}
// var questions = getElementById('#questions')
// async function pokeImage(){
// const pokeImage = await fetch('https://pokeapi.co/api/v2/pokemon/bulbasaur')
// console.log(pokeImage)
// const pokeImageData = await pokeImage.json();
// console.log(pokeImageData.sprites.front_shiny);
// const html = `<img id="pokeImg" src=${pokeImageData.sprites.front_shiny}> `
// container.insertAdjacentHTML("beforeend",html);
// }
// pokeImage();
// const pokeFinder = async function() {
// const poki = await getPokeData();
// // const pokePoke = await axios.get(poki.url);
// const pokemonImg = await pokePoke.data.results
// // console.log(pokemonImg);
// }
//getting fetch request
// const pokemonImg = await axios.get(pokemon.url)
// const pokemonImg = await pokemon.sprites.other['official-artwork'].front_default;
// const anything = await pokemonImg.data.results;
// getting access to the pokemon
// const pokemonImg = await https://pokeapi.co/api/v2/pokemon/39/;
// pokeFinder();
// const gameLogic = async function(){
// const {name, url} = await getPokeData();
// console.log(name, url);
// //post a pic of pokemon
// //ask user what pokemon this is
// // let question = prompt("What pokemon is this");
// //check if answer is correct
//
// //if not correct prompt guess again
// }
// }
// gameLogic();
// making a button to give me the random pokemon
// playbtn.addEventListener('click', gameLogic);
// }