-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_1.html
39 lines (37 loc) · 991 Bytes
/
code_1.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
<!DOCTYPE html>
<html>
<head>
<title>Random Pokemon Generator</title>
<style>
html {
font-family: 'Futura';
}
#content {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 8vw;
text-transform: uppercase;
}
</style>
</head>
<body>
<div id="content"></div>
<script type="text/javascript">
function reqListener () {
var response = JSON.parse(this.responseText);
console.log(response);
document.getElementById("content").innerHTML = response.name;
}
function generateRandomNumber () {
return Math.floor(Math.random() * 151 + 1);
}
var request = new XMLHttpRequest();
var pokeAPI = "http://pokeapi.co/api/v2/pokemon/";
request.addEventListener("load", reqListener);
request.open("GET", pokeAPI + generateRandomNumber() + "/");
request.send();
</script>
</body>
</html>