-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (60 loc) · 1.74 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pokedex</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<style>
body{
/* background-color: black; */
}
#pokedex {
height:180px ;
}
</style>
</head>
<body>
<main><!--this is like the wrapper-->
<div id="pokedex"></div>
<div id="content"></div>
</main>
<script>
$(document).ready( function (){
var content = $('#content');
var pokedex = $('#pokedex');
var id = 0;
for (var i = 1; i <= 151; i++) {
content.append("<img data-rel='"+i+"' src="+"'http://pokeapi.co/media/img/"+i+".png'>");
};
function findPokemon(id){
$.get("http://pokeapi.co/api/v2/pokemon/"+id, function(res) {
var pokemon ={};
pokemon = res;
console.log (pokemon.name, pokemon.weight, pokemon.height,pokemon.types[0].type.name );
var html_str = "";
html_str += "<h2>"+pokemon.name+"</h3>"
html_str += "<h4>Height</h4>"
html_str += "<p>"+pokemon.height+"</p>"
html_str += "<h4>Weight</h4>"
html_str += "<p>"+pokemon.weight+"</p>"
html_str += "<h4>Types</h4>";
html_str += "<ul>";
for(var i = 0; i < pokemon.types.length; i++) {
html_str += "<li>" + pokemon.types[i].type.name + "</li>";
}
html_str += "</ul>";
pokedex.append(html_str);
}, "json");
}// closes findPokemon
// now program the click event
$( "img" ).click(function() {
var id = $(this).attr("data-rel")
console.log(id);
findPokemon(id);
});
// findPokemon(25); //
});// closes the ready function
</script>
</body>
</html>