forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmike-example.html
More file actions
40 lines (38 loc) · 1023 Bytes
/
mike-example.html
File metadata and controls
40 lines (38 loc) · 1023 Bytes
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
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener("load", () => {
const form = document.getElementById("form");
form.addEventListener("submit", (event) => {
const searchTerm = document.getElementById("search-term");
event.preventDefault();
console.log(searchTerm);
fetch(`https://pokeapi.co/api/v2/pokemon/${searchTerm.value}`).then(
(response) => {
response.json().then((json) => {
const content = document.getElementById("content");
content.innerHTML = `
<h2>${json.name}</h2>
<img src='${json.sprites.front_default}' />
<p>Id:<b>${json.id}</b></p>
`;
});
}
);
});
});
</script>
</head>
<body>
<h1>Pokedex</h1>
<form id="form">
<label
>Search:
<input type="text" id="search-term" />
</label>
<input type="submit" value="Go!" />
</form>
<div id="content"></div>
</body>
</html>