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
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
## SEIR 0911EC

### PokeAPI lab

<img src="./assets/pokemon1.jpeg">

Let's be the very best, that no one ever was.
To make API calls is our quest
DOM Manipulation is our cause!


For this lab lets create our own Pokedex by making an Axios call to the PokeAPI!
Lets first create an html file, attach in our JS Script file and the Axios library, and enter in a search bar and button to submit in our API call
We can put in some empty HTML elements as well to populate with our response data, in this case just an H2 and an Image, but we can put in as much as we want once we get our calls made. Scaffold in a CSS file to add some style once the data is rendered on screen too!


Explore the https://pokeapi.co/ API with ThunderClient to see what types of endpoints are available, and what your data will look like

You may need to Map through and run some conditionals for some peices of information (abilities, types...) if you want to put in additional peices of API data

```html
<form>
<input type="text" value="" placeholder="Enter text here" id="inputBar">
<input type="text" value="" placeholder="Choose your pokemon!" id="inputBar">
<input type="button" value="Click here" id="searchButton">
</form>

Expand All @@ -29,16 +39,25 @@ let button = document.querySelector("#searchButton")

button.addEventListener('click', async () => {

let textInput = document.querySelector("#inputBar").value
let pokemonName = document.querySelector("#pokemonName")
let pokemonImage = document.querySelector("#pokemonImage")

//where does this need to be scoped?
let textInput = document.querySelector("#inputBar").value


//Axios call goes here
//remember to use Await!
//remember to use Async and Await!
//DOM Setters go here

}

)

```

Once you have the initial data rendered, try to add as much as possible. We can search Pokemon by names and numbers, can we also search for Moves, Berries, and other information?


Finally, this is a chance to really explore your styling skills. Be sure to create some wireframes to work with before creating something you can really show off, and have fun with!


<img src="./assets/pokedex-3.jpeg">
Binary file added assets/pokedex-3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/pokemon1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">
<title>Document</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script defer src="script.js"></script>
</head>
<body>
<header>
<!-- <img src="./assets/bahnijit-barman-1fZC2rYbpsU-unsplash.jpg" alt="pokemon picture" id="header-img"> -->
</header>

<form>
<input type="text" value="" placeholder="choose your pokemon!" id="inputBar">
<input type="button" value="click here" id="searchButton">
</form>

<!-- <img id="pokemonImage"> -->
<div id="pokemonImage"></div>
<h2 id="pokemonName"></h2>

</body>
</html>
69 changes: 69 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const button = document.querySelector('#searchButton')
const textInput = document.querySelector('#inputBar')
const pokemonName = document.querySelector('#pokemonName')
const pokemonImage = document.querySelector('#pokemonImage')


button.addEventListener('click', async () => {
//Remove elements with ability id
let toRemove = document.querySelectorAll('.blue')
if(toRemove){
toRemove.forEach((el) => el.remove())
}
//Text value from input bar
let pokeInput = textInput.value.toLowerCase()
let response = await axios.get(`https://pokeapi.co/api/v2/pokemon/${pokeInput}`)
console.log(response)
//name code
let pokeName = response.data.name
pokemonName.innerHTML = pokeName
//image code
let pokeImage = response.data.sprites.front_default
pokemonImage.innerHTML = `<img src=${pokeImage}>`
//stats
//stats header
let statsHeader = document.createElement('h3')
statsHeader.setAttribute('class', 'blue')
statsHeader.append(`stats`)
//height div
let pokeHeight = response.data.height
let heightDiv = document.createElement('div')
heightDiv.setAttribute('class', 'blue stats')
heightDiv.append(`${pokeHeight} poke-units tall`)
//weight div
let pokeWeight = response.data.weight
let weightDiv = document.createElement('div')
weightDiv.setAttribute('class', 'blue stats')
weightDiv.append(`weighs ${pokeWeight} poke-units`)
document.body.append(statsHeader, heightDiv, weightDiv)
//abilities div creation
let pokeAbilities = response.data.abilities
if (pokeAbilities.length > 0){
let newHeader = document.createElement('h3')
newHeader.setAttribute('class', 'blue')
newHeader.append(`${pokeName}'s abilities`)
document.body.append(newHeader)
}
pokeAbilities.forEach((ab) => {
let abilityName = ab.ability.name
let newDiv = document.createElement('div')
newDiv.setAttribute('class', 'abilities blue')
newDiv.append(abilityName)
document.body.append(newDiv)
})
//held items
let pokeHeld = response.data.held_items
if (pokeHeld.length > 0){
let newHeader = document.createElement('h3')
newHeader.setAttribute('class', 'blue')
newHeader.append(`${pokeName}'s held items`)
document.body.append(newHeader)
}
pokeHeld.forEach((itm) => {
let itemHeld = itm.item.name
let newDiv = document.createElement('div')
newDiv.setAttribute('class', 'held-item blue')
newDiv.append(itemHeld)
document.body.append(newDiv)
})
})
63 changes: 63 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
header {
width: 100%;
}

body {
background-color: #102a25;
/* color: #eeeced; */
color: #eeeced;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Roboto Mono', monospace;
}

h2 {
color: #1a1a19;
margin-top: -50px;
}

h3 {
color:#debd29;
font-size: 24px;
padding: 20px 0 5px 0;
border-bottom: 2px solid #eeeced;
}

img {
margin: auto;
margin-top: 20px;
height: 30vh;
width: 30vh;
border-radius: 5px;
background-color: #eeeced;
border: 20px solid #dbd1c2;
border-bottom: 50px solid #dbd1c2;
}

form {
display: flex;
flex-direction: column;
align-content: center;
margin-top: 5%;
}

#inputBar, #searchButton {
text-align: center;
padding: 5px 30px;
margin: 2px;
font-family: 'Roboto Mono', monospace;
background-color: #dbd1c2;
color: #1a1a19;
border: 1px solid #1a1a19;
border-radius: 5px;
}

#searchButton:hover {
background-color: #debd29;
}

.blue {
margin: 5px 0;
}