HCDD 411
1 / 21

API Practice Problems

HCDD 411

20 problems — from guided to independent

🟢 Easy (1–5)

Step-by-step TODOs. Every line is scaffolded for you.

🔵 Easy-Medium (6–10)

Less scaffolding. A few hints to point you in the right direction.

🟡 Medium (11–15)

Minimal hints. You're mostly on your own — think it through.

🔴 Medium-Hard (16–20)

No scaffolding. Multi-step problems that combine concepts.

All examples use: https://jsonplaceholder.typicode.com — a free fake REST API, perfect for practice.
Problem 1 of 20
🟢 Easy

Fetch a User's Name

Your Task:
  • Use fetch() to GET user #1 from the API
  • Parse the JSON response
  • Log the user's name to the console
PRACTICE 1: Fetch GET – user name
📄 p01-fetch-name.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hints:
  • Replace ??? with user.name
  • Expected output: Leanne Graham
Problem 2 of 20
🟢 Easy

Parse a JSON String

Your Task:
  • Use JSON.parse() to convert the string below into a JS object
  • Log the title and userId fields
  • Then use JSON.stringify() to convert the object back to a string and log it
PRACTICE 2: JSON.parse + JSON.stringify
📄 p02-json.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hints:
  • JSON.parse(raw) → turns a string into an object
  • JSON.stringify(obj) → turns an object back into a string
  • Access properties with dot notation: obj.title, obj.userId
Problem 3 of 20
🟢 Easy

jQuery AJAX — Fetch a Post

Your Task:
  • Use $.ajax() to GET post #5 from the API
  • In the success callback, log the post's title
  • Add an error callback that logs "Request failed"
PRACTICE 3: $.ajax GET
📄 p03-ajax.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hints:
  • Inside success, the parsed object arrives as data
  • The title field is data.title
  • Expected output: nesciunt quas odio
Problem 4 of 20
🟢 Easy

Fetch a User's Email

Your Task:
  • Fetch user #3 from the API
  • Log both their name and email
  • Add proper error handling with if (!response.ok)
PRACTICE 4: Fetch GET – name + email
📄 p04-email.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hints:
  • Replace ??? with user.name and user.email
  • Expected name: Clementine Bauch
Problem 5 of 20
🟢 Easy

Fetch a Todo — async/await

Your Task:
  • Use async/await with Fetch to GET todo #7
  • Log the title and whether it is completed
PRACTICE 5: async/await – todo
📄 p05-todo.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hints:
  • Fill in the URL string and replace ??? with todo.completed
  • Expected output: illo expedita consequatur quia in, Completed: false
Problem 6 of 20
🔵 Easy-Medium

Count All Posts

Your Task:
  • Fetch all posts from /posts (no ID — returns an array)
  • Log the total number of posts using .length
  • Also log the title of the first post in the array
PRACTICE 6: Fetch array + count
📄 p06-count.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Arrays have a .length property. Access index 0 with posts[0].title. Expected total: 100.
Problem 7 of 20
🔵 Easy-Medium

jQuery AJAX — Create a Post

Your Task:
  • Use $.ajax() with method: "POST" to create a new post
  • Send a JSON body with title, body, and userId fields
  • Log the id of the newly created post from the response
PRACTICE 7: $.ajax POST
📄 p07-ajax-post.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: The API returns the new post object. The fake server always returns id: 101 for a POST to /posts.
Problem 8 of 20
🔵 Easy-Medium

Fetch POST with Headers

Your Task:
  • Use fetch() with method: "POST"
  • Include the correct Content-Type header
  • Send a JSON-serialized body using JSON.stringify()
  • Log the returned id and title
PRACTICE 8: Fetch POST + headers
📄 p08-fetch-post.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: The Content-Type header value is "application/json". Write it as "Content-Type": "application/json" inside the headers object.
Problem 9 of 20
🔵 Easy-Medium

Axios GET — User Details

Your Task:
  • Use axios.get() to fetch user #4
  • Log the user's name, phone, and website
  • Remember: with Axios the data lives in response.data, not response directly
PRACTICE 9: Axios GET – user details
📄 p09-axios-get.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Fields are user.name, user.phone, user.website. Expected name: Patricia Lebsack.
Problem 10 of 20
🔵 Easy-Medium

Filter Completed Todos

Your Task:
  • Fetch all todos from /todos
  • Filter the array to only keep todos where completed === true
  • Log how many completed todos there are and the title of the first one
PRACTICE 10: Fetch + array filter
📄 p10-filter.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Array.filter() returns a new array with only the items that pass the condition. Expected completed count: 90.
Problem 11 of 20
🟡 Medium

Chain Two Requests — User → Posts

Your Task:
  • Fetch user #2
  • Using the user's id, fetch all posts by that user: /posts?userId=<id>
  • Log the user's name and how many posts they have
PRACTICE 11: Chained requests
📄 p11-chain.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Build the URL like: "...typicode.com/posts?userId=" + user.id. Expected: Ervin Howell, 10 posts.
Problem 12 of 20
🟡 Medium

Search Users by Name

Your Task:
  • Fetch all users from /users
  • Filter by a keyword — keep only users whose name contains "ch" (case-insensitive)
  • Log each matching user's name and email
PRACTICE 12: Filter by name keyword
📄 p12-search.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Use user.name.toLowerCase().includes(k) as the filter condition.
Problem 13 of 20
🟡 Medium

Axios POST — Create a Comment

Your Task:
  • Use axios.post() to create a new comment on post 1
  • The body should include: postId, name, email, body
  • Log the full response object that comes back
PRACTICE 13: Axios POST – comment
📄 p13-axios-post.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Hint: Axios syntax: axios.post(url, bodyObject). The response data is at response.data. No need to call JSON.stringify() — Axios handles that.
Problem 14 of 20
🟡 Medium

Three-Step Chain — Post → Comments → Count

Your Task:
  • Fetch post #3
  • Then fetch all comments for that post: /comments?postId=<id>
  • Log the post title, and how many comments it has
  • Also log the email of the first commenter
PRACTICE 14: 3-step chain
📄 p14-three-chain.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Problem 15 of 20
🟡 Medium

Promise Chain (no async/await)

Your Task:
  • Fetch user #5 using only .then() and .catch() — no async/await
  • In the first .then(), check response.ok and call response.json()
  • In the second .then(), log the user's name and company name (user.company.name)
PRACTICE 15: Pure .then() chain
📄 p15-then-chain.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Problem 16 of 20
🔴 Medium-Hard

Reusable Helper + User Albums

Your Task:
  • Write a reusable fetchJson(url) async helper function
  • Use it to: fetch user #1, then fetch all albums for that user (/albums?userId=<id>)
  • Log the user's name, total albums, and the title of every album
PRACTICE 16: Custom helper + chained data
📄 p16-helper.js
Ln 1, Col 1 JavaScript
💻 Console Output:
No hints. You have all the pieces from the earlier problems. Put them together.
Problem 17 of 20
🔴 Medium-Hard

Parallel Requests with Promise.all

Your Task:
  • Fetch users #1 and #2 at the same time using Promise.all()
  • Only after both resolve, log both users' names side by side
  • Add error handling — if either fails, log the error
PRACTICE 17: Promise.all – parallel fetches
📄 p17-parallel.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Problem 18 of 20
🔴 Medium-Hard

Full Pipeline — User → Posts → Comments

Your Task:
  • Fetch user #1
  • Then fetch all posts by that user
  • Then, for the first post only, fetch its comments
  • Log: user name, first post title, comment count, and all commenter emails
PRACTICE 18: 3-resource pipeline
📄 p18-pipeline.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Problem 19 of 20
🔴 Medium-Hard

POST then Verify — Create & Echo

Your Task:
  • Create a new post using a POST request
  • Log the id returned by the server
  • Then immediately make a second GET request to /posts/1 to read an existing post
  • Log both: "Created ID" from the POST, and "Verified title" from the GET
  • All of this inside one async function with proper error handling
PRACTICE 19: POST then GET
📄 p19-post-then-get.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Problem 20 of 20
🔴 Medium-Hard

Graceful Error Handling + Retry

Your Task:
  • Write an async function fetchWithRetry(url, retries)
  • It should try to fetch the URL up to retries times
  • If a fetch attempt throws, log "Attempt N failed" and try again
  • If all attempts fail, log "All attempts failed"
  • Test it by calling it with a bad URL first, then with a good one
PRACTICE 20: Retry logic
📄 p20-retry.js
Ln 1, Col 1 JavaScript
💻 Console Output:
Challenge: The fake API returns 200 even for unknown resources. Use if (!res.ok) throw new Error(...) inside your loop to force a real failure, then test with a valid endpoint to confirm success.