Last active
December 10, 2018 08:54
-
-
Save harrisonmalone/06ac2ae0246b621677c7acc50af1b123 to your computer and use it in GitHub Desktop.
practised with this before taking bootstrap class with anz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | |
<style> | |
.wrapper { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
max-width: 600px; | |
height: 80vh; | |
margin: 0 auto; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- <h3>HTML Form</h3> | |
<div> | |
<label for="email">Email</label> | |
<input type="email" placeholder="Enter email"> | |
<label for="password">Password</label> | |
<input type="password" name="password" placeholder="Enter password"> | |
<button type="submit">Submit</button> | |
</div> --> | |
<div class="wrapper"> | |
<!-- <form> | |
<h3>Sign in</h3> | |
<div class="form-group"> | |
<label for="email">Email</label> | |
<input type="email" class="form-control" placeholder="Enter email"> | |
</div> | |
<div class="form-group"> | |
<label for="password">Password</label> | |
<input type="password" class="form-control" placeholder="Enter password"> | |
</div> | |
<div class="form-group"> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</div> | |
</form> --> | |
<form> | |
<div class="form-group"> | |
<label>Get pokemon</label> | |
<input type="text" class="form-control" placeholder="Enter pokemon name"> | |
</div> | |
<div class="form-group"> | |
<input type="submit" value="Submit" class="btn btn-primary"></input> | |
</div> | |
</form> | |
</div> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const form = document.querySelector('form') | |
form.addEventListener("submit", (event) => { | |
event.preventDefault() | |
const pokemon = event.currentTarget.elements[0].value | |
getPokemonData(pokemon) | |
}) | |
const getPokemonData = (pokemon) => { | |
const url = `https://pokeapi.co/api/v2/pokemon/${pokemon}/` | |
fetch(url) | |
.then((response) => { | |
const json = response.json() | |
return json | |
}) | |
.then((data) => { | |
appendPokemon(data) | |
}) | |
} | |
const appendPokemon = (data) => { | |
const body = document.querySelector('.wrapper') | |
console.log(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment