-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainer.js
54 lines (52 loc) · 2.21 KB
/
trainer.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
// -------> TRAINER CLASS GOES HERE
$("#btnPink").prop("disabled", true);
$("#btnYellow").prop("disabled", true);
let allAjaxDone = 0;
let doneLoading = false;
class trainerClass {
constructor(pokemon1,pokemon2,pokemon3, trainerName, profilePic) {
this.myPokemonNames = [pokemon1,pokemon2,pokemon3];
this.myPokemonObjects = [];
this.trainerName = trainerName;
this.profilePic = profilePic;
}
getMyPokemon() {
var self = this;
console.log(`STARTING ${this.trainerName.toUpperCase()}'S AJAX CALL`);
this.myPokemonNames.forEach(pokemon=>{
$.ajax({
url: "https://pokeapi.co/api/v2/pokemon/" + pokemon
}).done((result)=>{
self.myPokemonObjects.push(result);
if (self.myPokemonObjects.length === self.myPokemonNames.length) {
console.log(`${self.trainerName.toUpperCase()}'s AJAX CALLS COMPLETELY DONE`);
allAjaxDone ++;
$("#caption").text(`${allAjaxDone} out of ${safronGym.length} trainers loaded...`);
if (allAjaxDone === safronGym.length) {
console.log("ALL AJAX CALLS DONE");
setTimeout(()=>{
$("#caption").text("CLICK LEFT AND RIGHT TO SEE OUR TRAINERS");
},1500);
$("#btnPink").prop("disabled", false);
$("#btnYellow").prop("disabled", false);
doneLoading = true;
}
}
}).fail((result)=> {
console.log("failed");
});
});
}
}
let kanye = new trainerClass("bulbasaur","meowth","squirtle", "kanye", "kanyePic.jpg");
let messi = new trainerClass("victini", "butterfree", "mimikyu-disguised", "messi", "messiPic.jpg");
let jorge = new trainerClass("voltorb", "geodude", "poliwag", "jorge", "jorgePic.jpg");
kanye.getMyPokemon();
messi.getMyPokemon();
jorge.getMyPokemon();
let safronGym = [kanye,jorge,messi];
console.log("ARRAY OF ALL 3 TRAINERS:");
console.log(safronGym);
console.log("-------------------");
console.log("-------------------");
console.log("-------------------");