Skip to content

Instantly share code, notes, and snippets.

@ColinGreybosh
Last active December 4, 2018 06:38
Show Gist options
  • Save ColinGreybosh/f9f99f064f8b8c603e6db55c3f27b1cc to your computer and use it in GitHub Desktop.
Save ColinGreybosh/f9f99f064f8b8c603e6db55c3f27b1cc to your computer and use it in GitHub Desktop.
API Project Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Site</title>
<link rel="stylesheet" href="../CSS/StyleSheet.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h1>API Project</h1>
<div id="API">PokeAPI: <br><br>
Type in a Pokemon's Name to get its Information (all lowercase):<br><br>
<input type="text" name="input" id="input">
<br>
<input type="submit" onclick="pokeFunction()"> </div>
<p id="Poke"></p>
<script>
function pokeFunction() {
var pokemon = document.getElementById("input").value;
jQuery(document).ready(function($) {
$.ajax({
url : "https://pokeapi.co/api/v2/pokemon/"+pokemon+"/",
dataType : "json",
success : function(write) {
speed = write["stats"][0]["base_stat"];
specialdefense = write["stats"][1]["base_stat"];
specialattack = write["stats"][2]["base_stat"];
defense = write ["stats"][3]["base_stat"];
attack = write ["stats"][4]["base_stat"];
hp = write ["stats"][5]["base_stat"];
weight = write ["weight"];
type = write ["types"][0]["type"]["name"];
if (pokemon != null) {
document.getElementById("Poke").innerHTML =
"Type :" + type + "<br>" +
"Weight :" + weight + "<br>" +
"HP : " + hp + "<br>" +
"Attack : " + attack + "<br>" +
"Defense : " + defense + "<br>" +
"Special Attack : " + specialattack + "<br>" +
"Speical Defense : " + specialdefense + "<br>" +
"Speed : " + speed + "<br>" ;
}
}
});
});
}
</script>
</body>
</html>
@ColinGreybosh
Copy link
Author

@DavidGreybosh It should work now. Notice the changes that I made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment