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";

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 Pearl

Exercise 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 search

  • exercise2.js - Tea details

  • exercise3.js - Order calculator

  • exercise4.js - Stock check

  • exercise5.js - Full order flow

  • exercise6.js - Authenticated orders (optional)

Each file should be runnable with node exerciseN.js.

Last updated