Calculator Tools Calculator Tools
Create

Pokédex Lookup

Jan 7, 2024

About this app

Lookup Pokémon by National Dex number

Pokédex Lookup Pokédex Lookup Enter National Dex Number: Lookup Pokémon Stat Value

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Pokédex Lookup</title>
<meta name="description" content="Lookup Pokémon by National Dex number">
<meta name="keywords" content="Pokémon, National Dex, Pokédex, Lookup">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">

<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.

// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Function to fetch Pokémon data from the API
function fetchPokemonData(nationalDexNumber) {
$.ajax({
url: `https://pokeapi.co/api/v2/pokemon/${nationalDexNumber}`,
method: "GET",
success: function (response) {
// Extracting the necessary data
let name = response.name;
let image = response.sprites.front_default;
let gameVersion = response.game_indices[0].version.name;
let dexEntry = response.species.url;
let baseStats = response.stats;

// Displaying the Pokémon data
$("#pokemon-name").text(name);
$("#pokemon-image").attr("src", image);
$("#game-version").text(`Debut Game: ${gameVersion}`);
$("#base-stats").empty();

// Displaying the base stats
baseStats.forEach(function (stat) {
let statName = stat.stat.name;
let statValue = stat.base_stat;

let statRow = `<tr>
<td>${statName}</td>
<td>${statValue}</td>
</tr>`;
$("#base-stats").append(statRow);
});

// Fetching the dex entry from the game it debuted in
$.ajax({
url: dexEntry,
method: "GET",
success: function (response) {
let dexEntryText = response.flavor_text_entries[0].flavor_text;
$("#dex-entry").text(dexEntryText);
},
error: function (error) {
console.log("Error fetching dex entry:", error);
}
});
},
error: function (error) {
console.log("Error fetching Pokémon data:", error);
}
});
}

// Event listener for form submission
$("#pokemon-form").on("submit", function (event) {
event.preventDefault();
let nationalDexNumber = $("#dex-number").val();

// Validating the entered Dex number
if (nationalDexNumber >= 1 && nationalDexNumber <= 1025) {
fetchPokemonData(nationalDexNumber);
} else {
alert("Please enter a valid National Dex number between 1 and 1025.");
}
});
});

} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>

<style>
/* App CSS Goes Here */
body {
font-family: 'Roboto', sans-serif;
background-color: #f8f9fa;
color: #333333;
}

.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}

h1 {
font-size: 24px;
font-weight: 700;
margin-bottom: 20px;
text-align: center;
}

form {
margin-bottom: 20px;
}

.form-control {
margin-bottom: 10px;
}

.pokemon-card {
background-color: #ffffff;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.pokemon-card img {
display: block;
margin: 0 auto;
width: 150px;
height: 150px;
object-fit: contain;
margin-bottom: 20px;
}

.pokemon-details {
margin-bottom: 20px;
}

#base-stats-table {
width: 100%;
margin-bottom: 10px;
}

#base-stats-table th {
text-align: left;
}

#base-stats-table td {
padding: 5px 0;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Pokédex Lookup</h1>

<form id="pokemon-form">
<div class="form-group">
<label for="dex-number">Enter National Dex Number:</label>
<input type="number" class="form-control" id="dex-number" min="1" max="1025" required>
</div>
<button type="submit" class="btn btn-primary">Lookup Pokémon</button>
</form>

<div id="pokemon-details" class="pokemon-card">
<h2 id="pokemon-name" class="text-center"></h2>
<img id="pokemon-image" src="" alt="Pokémon Image">
<p id="game-version" class="text-center"></p>
<table id="base-stats-table">
<thead>
<tr>
<th>Stat</th>
<th>Value</th>
</tr>
</thead>
<tbody id="base-stats">
</tbody>
</table>
<p id="dex-entry"></p>
</div>
</div>
</body>
</html>