-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
62 lines (57 loc) · 2.02 KB
/
Copy pathscripts.js
File metadata and controls
62 lines (57 loc) · 2.02 KB
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
$(document).ready(function () {
$("#searchButton").click(function (e) {
var param = $("#searchField").val().toLowerCase();
console.log(param);
var pokeURL = "https://pokeapi.co/api/v1/pokemon/" + param + "/";
// new URL for 3rd GET request
var pokeURL2 = "https://pokeapi.co/api/v2/pokemon/" + param + "/";
$.ajax({
type: "GET",
url: pokeURL2,
datatype: "jsonp",
success: function (data) {
console.log(data);
var pokeid = data.id;
console.log(pokeid);
var pokename = data.name;
console.log(pokename);
var poketype1 = data.types[0].type.name;
console.log(poketype1);
if (data.types.length == 2) {
var poketype2 = data.types[1].type.name;
console.log(poketype2);
}
else var poketype2 = null;
var descriptionuri = data.species.url;
console.log(descriptionuri);
var sprite = data.sprites.front_default;
var resultsToHTML = "<img src=\"" + sprite + "\" alt=\"Pokemon Image\">";
resultsToHTML += "<br><h3>" + "#" + pokeid + ": " + pokename.charAt(0).toUpperCase() + pokename.slice(1) + "</h3>";
resultsToHTML += "<p> Type: " + poketype1;
if (data.types.length == 2) {
resultsToHTML += "/" + poketype2;
}
resultsToHTML += "</p>";
console.log("displayed the Pokemon");
var pokedescription = "";
$.ajax({
type: "GET",
url: descriptionuri,
datatype: "jsonp",
success: function (data2) {
console.log(data2);
if (data2.flavor_text_entries[1].language.name != "en") {
pokedescription = data2.flavor_text_entries[2].flavor_text;
}
else {
pokedescription = data2.flavor_text_entries[1].flavor_text;
}
console.log(pokedescription);
resultsToHTML += "<p>" + pokedescription + "</p>";
$(pokemon).html(resultsToHTML);
}
});
}
});
})
});