Student starter code (30% baseline)
index.html
- Main HTML pagescript.js
- JavaScript logicstyles.css
- Styling and layoutpackage.json
- Dependenciessetup.sh
- Setup scriptREADME.md
- Instructions (below)๐ก Download the ZIP, extract it, and follow the instructions below to get started!
Explore JSON parsing and API integration through hands-on discovery! This activity challenges you to research, experiment, and implement API integration patterns using the Pokemon API.
Through guided research and experimentation, you will:
python3 -m http.server 8000
Challenge One: API Communication ๐
Challenge 2: Random Data Generation ๐ฒ
Challenge 3: Data Format Exploration ๐
Challenge 4: Nested Object Navigation ๐งฉ
Challenge 5: Large Array Processing โก
Challenge 6: Dynamic Styling Integration ๐จ
Challenge 7: Concurrent Request Management ๐
Challenge 8: Complex System Orchestration ๐
The Pokemon API returns complex JSON with this structure:
{
"id": 25,
"name": "pikachu",
"height": 4,
"weight": 60,
"types": [
{
"slot": 1,
"type": {
"name": "electric",
"url": "https://pokeapi.co/api/v2/type/13/"
}
}
],
"stats": [
{
"base_stat": 35,
"effort": 0,
"stat": {
"name": "hp",
"url": "https://pokeapi.co/api/v2/stat/1/"
}
}
],
"moves": [...], // 100+ moves
"sprites": {
"front_default": "image_url"
}
}
// Accessing nested properties
const pokemonName = data.name;
const firstType = data.types[0].type.name;
const hpStat = data.stats[0].base_stat;
// Processing arrays
const typeNames = data.types.map(type => type.type.name);
const statValues = data.stats.map(stat => stat.base_stat);
// Filtering arrays
const firstTenMoves = data.moves.slice(0, 10);
const attackMoves = data.moves.filter(move =>
move.move.name.includes('attack')
);
Start with TODO 1 - Pokemon Search
// API endpoint to use:
`https://pokeapi.co/api/v2/pokemon/${pokemonName}`
// Basic pattern:
const response = await fetch(url);
const data = await response.json();
currentPokemonData = data;
displayPokemonCard(data);
Complete TODO 2 - Random Pokemon
// Generate random ID:
const randomId = Math.floor(Math.random() * 1010) + 1;
// Use same API pattern as TODO 1
Finish TODO 3 - Raw JSON
// Format JSON for display:
JSON.stringify(currentPokemonData, null, 2)
TODO 4: Stats Parsing
// Extract stats array:
const stats = currentPokemonData.stats;
// Process each stat:
stats.forEach(stat => {
const name = stat.stat.name;
const value = stat.base_stat;
// Display them
});
TODO 5: Moves Parsing
// Get first 10 moves:
const moves = currentPokemonData.moves.slice(0, 10);
// Extract move names:
const moveNames = moves.map(move => move.move.name);
TODO 6: Types Parsing
// Extract types:
const types = currentPokemonData.types;
// Create styled type badges:
types.map(type =>
`<span class="type-${type.type.name}">${type.type.name}</span>`
);
TODO 7: Comparison
// Fetch multiple Pokemon:
const [data1, data2] = await Promise.all([
fetch(`/pokemon/${pokemon1}`).then(r => r.json()),
fetch(`/pokemon/${pokemon2}`).then(r => r.json())
]);
TODO 8: Team Builder
// Generate multiple random IDs:
const ids = [1, 2, 3].map(() =>
Math.floor(Math.random() * 1010) + 1
);
// Fetch all at once:
const teamData = await Promise.all(
ids.map(id => fetch(`/pokemon/${id}`).then(r => r.json()))
);
Basic Functionality:
Data Parsing:
Advanced Features:
"Pokemon not found" errors:
"Cannot read property" errors:
data?.types?.[0]?.type?.name
Empty displays:
Your project is complete when:
const { name, id } = pokemon;
map()
, filter()
, slice()
async/await
, Promise.all()
pokemon?.sprites?.front_default
console.log()
, console.table()
Upon completion, you'll have mastered:
This foundation prepares you perfectly for the next activity where we'll explore API authentication and work with multiple APIs simultaneously!
Need Help?
console.log()
liberally to inspect data structuresRemember: The Pokemon API is free, fast, and doesn't require authentication - perfect for learning! ๐ฏโก