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!
Welcome to your second API integration project! This template helps you master JSON parsing and data manipulation using the Pokemon API's rich data structures.
By completing this activity, you will:
IMPORTANT: This template includes WORKING CODE! You can see it in action immediately:
# Mac/Linux:
python3 -m http.server 8000
# Windows:
python -m http.server 8000
# Alternative using Node.js:
npx http-server -p 8000
65% of the code is implemented for you:
Complete the searchPokemon() function to fetch and display Pokemon data.
API Endpoint: https://pokeapi.co/api/v2/pokemon/{pokemon-name}
Success Criteria:
Complete the getRandomPokemon() function to fetch a random Pokemon from the first 1010.
Requirements:
Complete the showRawJson() function to show formatted API responses.
Purpose:
Success Criteria:
Complete the parseStats() function to extract and display Pokemon base stats.
Data Structure:
data.stats = [
{
base_stat: 35,
stat: { name: "hp" }
},
// ... more stats
]
Success Criteria:
Complete the parseMoves() function to extract and display the first 10 moves.
Data Structure:
data.moves = [
{
move: {
name: "thunder-shock",
url: "..."
}
},
// ... 100+ more moves
]
Success Criteria:
Complete the parseTypes() function to extract and display Pokemon types with styling.
Data Structure:
data.types = [
{
slot: 1,
type: {
name: "electric",
url: "..."
}
}
]
Success Criteria:
type-electric)Complete the comparePokemon() function to fetch and display two Pokemon side-by-side.
Requirements:
Hint: Use this pattern for concurrent requests:
const [data1, data2] = await Promise.all([
fetch(url1).then(r => r.json()),
fetch(url2).then(r => r.json())
]);
Complete the buildRandomTeam() function to generate a team of 3 random Pokemon.
Requirements:
Success Criteria:
https://pokeapi.co/api/v2// Get Pokemon by name or ID
GET https://pokeapi.co/api/v2/pokemon/{name-or-id}
// Examples:
// https://pokeapi.co/api/v2/pokemon/pikachu
// https://pokeapi.co/api/v2/pokemon/25
Pokemon Response (simplified):
{
"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": [
{
"move": {
"name": "mega-punch",
"url": "https://pokeapi.co/api/v2/move/5/"
}
}
],
"sprites": {
"front_default": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/25.png"
}
}
// Accessing basic properties
const name = data.name;
const height = data.height;
const weight = data.weight;
// Accessing nested properties
const firstType = data.types[0].type.name;
const firstStat = data.stats[0].base_stat;
const firstMove = data.moves[0].move.name;
// Processing arrays with map()
const allTypes = data.types.map(t => t.type.name);
const allStats = data.stats.map(s => s.base_stat);
const firstTenMoves = data.moves.slice(0, 10).map(m => m.move.name);
Basic Functionality:
Data Parsing:
Advanced Features:
Issue: "Pokemon not found" Solution: Use lowercase names ("pikachu" not "Pikachu")
Issue: "Cannot read property 'name' of undefined"
Solution: Check that the API response has the expected structure. Use optional chaining: data?.types?.[0]?.type?.name
Issue: CORS errors Solution: Use a local server (Python http.server) instead of opening HTML file directly
Issue: Empty displays after parsing Solution: Make sure you're calling the display functions and returning the HTML string
Ready for more? Try these bonus features:
map(), filter(), slice(), forEach()const { name, id } = pokemon;Your project is complete when:
Once you complete this project, you'll have:
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() to inspect data structuresHappy coding! โกโจ