Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions complex-api-bootcamp
Submodule complex-api-bootcamp added at 87166f
Empty file added css/styles.css
Empty file.
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GOT</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Find Your Game of Thrones Character!</h1>

<!-- <label id="character"> Enter Character: </label>
<input class="input" type="text" placeholder="Name"> -->

<select id="characters" name="characters">
<option value="Sansa Stark">Sansa Stark</option>
<option value="Arya Stark">Arya Stark</option>
<option value="Jon Snow">Jon Snow</option>
<option value="Daenerys Targaryen">Daenerys Targaryen</option>
<option value="Cersei Lannister">Cersei Lannister</option>
<option value="Tyrion Lannister">Tyrion Lannister</option>
</select>

<h2></h2>
<img id="charImg" src="" alt="">

<div id="charImg"></div>



<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Goal: Use data returned from one api to make a request to another api and display the data returned
// User enters GOT character
// listen for on'click
// fetch for the character info (first name, last name) from 1st API

// once information show up, a second api will populate a character's image.


const select = document.getElementById('characters');
const nameDisplay = document.querySelector('h2');
const img = document.getElementById('charImg');

select.addEventListener('change', function() {
const charName = select.value;

fetch('https://thronesapi.com/api/v2/Characters')
.then(function(response) { return response.json(); })
.then(function(data) {
for (let i = 0; i < data.length; i++) {
if (data[i].fullName === charName) {
nameDisplay.innerText = data[i].fullName;
img.src = data[i].imageUrl;
}
}
return fetch('https://api.gameofthronesquotes.xyz/v1/characters');
})
.then(function(response) { return response.json(); })
.then(function(data2) {
console.log(data2);
})
.catch(function(err) {
console.error('Error:', err);
});
});
// completed with the help of Angie, Sylvie, chatgpt and MJ