Assignment
Build a Tea Shop CLI tool that interacts with the Tea Shop API.
const API_BASE = "https://tea-api-787553294298.europe-west1.run.app/api";Exercise 1: Tea Search
Create a function that searches for teas by name:
async function searchTeas(query) {
// 1. Fetch all teas from the API
// 2. Filter to teas where name includes query (case-insensitive)
// 3. Return array of matching tea objects
}
// Test it:
searchTeas("pearl").then((teas) => {
console.log("Search results for 'pearl':");
teas.forEach((tea) => console.log(`- ${tea.name}`));
});Expected output:
Search results for 'pearl':
- Jasmine Pearl
- Royal Kenya Pearl
- Imperial China Pearl
- Mountain Sri Lanka PearlExercise 2: Tea Details
Create a function that gets full details for a tea, including its current stock:
Exercise 3: Order Calculator ⭐
Create a function that calculates the total for an order:
Exercise 4: Stock Check ⭐
Create a function that checks if all items in an order are in stock:
Exercise 5: Full Order Flow ⭐⭐
Combine everything into a complete order processing flow:
Exercise 6: Authenticated Orders ⭐⭐
Create functions to work with the authenticated orders endpoint.
First, sign up for an account, then use login to get a token:
⚠️ Use a dummy email and password — not your real ones! This is a practice API with no security guarantees.
Submission
Create a folder week3-assignment/ with:
exercise1.js- Tea searchexercise2.js- Tea detailsexercise3.js- Order calculatorexercise4.js- Stock checkexercise5.js- Full order flowexercise6.js- Authenticated orders (optional)
Each file should be runnable with node exerciseN.js.
Last updated