Skip to content

Commit 5c512cb

Browse files
Clarify exercise requirements (#2)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 08c5610 commit 5c512cb

58 files changed

Lines changed: 553 additions & 495 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

exercises/01.promises/01.problem.creation/README.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ const fetchForecast = () =>
1616

1717
🐨 Open <InlineFile file="index.ts" /> and:
1818

19-
1. Create a `fetchUser` function that returns a `Promise<User>`
20-
2. The Promise should resolve after 1 second with a user object (you could do 10 milliseconds to make the tests faster if you want)
21-
3. The user object should have: `id: string`, `name: string`, `email: string`
19+
1. Create and export a `fetchUser` function that returns a `Promise<User>`
20+
2. Resolve after a short delay (about 1 second is fine; a few milliseconds is
21+
fine for faster checks)
22+
3. Resolve with this user fixture:
23+
- `id: '1'`
24+
- `name: 'Alice'`
25+
- `email: 'alice@example.com'`
26+
27+
Completion check: calling `await fetchUser()` returns that exact user object.
2228

2329
📜 [MDN - Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)

exercises/01.promises/01.problem.creation/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ type User = {
77
}
88

99
// 🐨 Create a function `fetchUser` that returns a Promise<User>
10-
// The Promise should resolve after 1 second with a user object
10+
// Resolve after a short delay with:
11+
// { id: '1', name: 'Alice', email: 'alice@example.com' }
1112

12-
// 🐨 Call fetchUser and log the result when it resolves
13-
14-
// 🐨 Export your function so we can verify your work
13+
// 🐨 Call fetchUser and log the result when it resolves (optional)
1514

15+
// 🐨 Export fetchUser so we can verify your work
1616
// export { fetchUser }

exercises/01.promises/01.solution.creation/index.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { test } from 'node:test'
33
import * as solution from './index.ts'
44

55
await test('fetchUser is exported', () => {
6-
assert.ok(
7-
'fetchUser' in solution,
8-
'🚨 Make sure you export "fetchUser" - add: export { fetchUser }',
9-
)
6+
assert.ok('fetchUser' in solution, '🚨 Make sure you export "fetchUser"')
107
})
118

129
await test(

exercises/01.promises/02.problem.chaining/README.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ fetchPlaylist()
2424

2525
🐨 Open <InlineFile file="index.ts" /> and:
2626

27-
1. Create `fetchUserAndOrders` to chain the promises and return `{ user, orders }`
28-
2. Export `fetchUserAndOrders`
27+
1. Create and export `fetchUserAndOrders` that:
28+
- Calls the provided `fetchUser`
29+
- Then calls `fetchOrders` with that user's `id`
30+
- Returns `{ user, orders }`
31+
2. Keep using `.then()` chaining for this step (no `async`/`await` yet)
32+
33+
Completion check: `await fetchUserAndOrders()` returns a user with `id: '1'`
34+
and an `orders` array whose first order has `userId` equal to that same id.
2935

3036
📜 [MDN - Promise.prototype.then()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)

exercises/01.promises/02.problem.chaining/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ function fetchOrders(userId: string): Promise<Array<Order>> {
4040
})
4141
}
4242

43-
// 🐨 Create fetchUserAndOrders() that chains the promises and returns:
44-
// { user, orders }
43+
// 🐨 Create fetchUserAndOrders() that:
44+
// 1. Calls fetchUser()
45+
// 2. Passes user.id into fetchOrders(userId)
46+
// 3. Returns Promise<{ user: User; orders: Array<Order> }>
4547

4648
// 🐨 verify your work with:
4749
// fetchUserAndOrders().then(({ user, orders }) => {
@@ -50,5 +52,4 @@ function fetchOrders(userId: string): Promise<Array<Order>> {
5052
// })
5153

5254
// 🐨 Export fetchUserAndOrders so we can verify your work
53-
5455
// export { fetchUserAndOrders }

exercises/01.promises/02.solution.chaining/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as solution from './index.ts'
55
await test('fetchUserAndOrders is exported', () => {
66
assert.ok(
77
'fetchUserAndOrders' in solution,
8-
'🚨 Make sure you export "fetchUserAndOrders" - add: export { fetchUserAndOrders }',
8+
'🚨 Make sure you export "fetchUserAndOrders"',
99
)
1010
})
1111

@@ -23,11 +23,11 @@ await test('promise chaining works correctly', { timeout: 5000 }, async () => {
2323
assert.strictEqual(
2424
result.user.id,
2525
'1',
26-
'🚨 user.id should be "1" - make sure you await fetchUser() first',
26+
'🚨 user.id should be "1" - fetch the user before fetching orders',
2727
)
2828
assert.strictEqual(
2929
result.orders[0].userId,
3030
result.user.id,
31-
'🚨 orders[0].userId should match user.id - chain promises correctly using .then() or await',
31+
'🚨 orders[0].userId should match user.id - pass the user id into fetchOrders',
3232
)
3333
})

exercises/01.promises/03.problem.rejection/README.mdx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ Rejected Promises should be caught so we can return a friendly error state.
77

88
🐨 Open <InlineFile file="index.ts" /> and:
99

10-
1. Update `getUserProfile` to handle rejections with `.catch()`
11-
2. Return an error result when the Promise rejects
12-
3. Keep the `id` parameter flowing through both functions
13-
4. Export `fetchUser` and `getUserProfile`
10+
1. Keep `fetchUser(id)` as provided:
11+
- `id === '1'` resolves to Alice (`id: '1'`, `name: 'Alice'`,
12+
`email: 'alice@example.com'`)
13+
- any other id rejects with `Error('User not found')`
14+
2. Update `getUserProfile(id)` to handle rejections with `.catch()`
15+
3. Return shapes:
16+
- success: `{ status: 'success', user }`
17+
- error: `{ status: 'error', message }` where `message` is
18+
`error.message` when the rejection is an `Error`, otherwise
19+
`'Unknown error'`
20+
4. Export both `fetchUser` and `getUserProfile`
1421

15-
💰 For the error result, return a `{ status: 'error', message: string }` object.
16-
If the value isn't an `Error`, use `'Unknown error'` as the message.
22+
Completion checks:
23+
24+
- `await getUserProfile('1')``{ status: 'success', user: { id: '1', ... } }`
25+
- `await getUserProfile('missing')`
26+
`{ status: 'error', message: 'User not found' }`
27+
- `await fetchUser('missing')` still rejects (do not swallow that rejection
28+
inside `fetchUser` itself)
1729

1830
📜 [MDN - Promise.prototype.catch()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)

exercises/01.promises/03.problem.rejection/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ function getUserProfile(id: string): Promise<UserProfile> {
3131
return fetchUser(id).then((user) => ({ status: 'success', user }) as const)
3232
}
3333

34-
// 🐨 Update getUserProfile to handle rejections and return an error status
35-
// 💰 return { status: 'error', message: error.message }
36-
// 💰 if error isn't an Error, use 'Unknown error'
34+
// 🐨 Update getUserProfile to handle rejections with .catch()
35+
// On rejection, return { status: 'error', message }
36+
// 💰 Prefer error.message when the rejection is an Error; otherwise
37+
// use 'Unknown error'
3738

3839
// 🐨 Export fetchUser and getUserProfile so we can verify your work
3940
// export { fetchUser, getUserProfile }

exercises/01.promises/03.solution.rejection/index.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import { test } from 'node:test'
33
import * as solution from './index.ts'
44

55
await test('fetchUser and getUserProfile are exported', () => {
6-
assert.ok(
7-
'fetchUser' in solution,
8-
'🚨 Make sure you export "fetchUser" - add: export { fetchUser, getUserProfile }',
9-
)
6+
assert.ok('fetchUser' in solution, '🚨 Make sure you export "fetchUser"')
107
assert.ok(
118
'getUserProfile' in solution,
12-
'🚨 Make sure you export "getUserProfile" - add: export { fetchUser, getUserProfile }',
9+
'🚨 Make sure you export "getUserProfile"',
1310
)
1411
})
1512

@@ -60,7 +57,7 @@ await test(
6057
assert.strictEqual(
6158
result.status,
6259
'success',
63-
'🚨 getUserProfile() should return status "success" when fetchUser resolves',
60+
'🚨 getUserProfile("1") should return status "success"',
6461
)
6562
if (result.status === 'success') {
6663
assert.strictEqual(
@@ -81,7 +78,7 @@ await test(
8178
assert.strictEqual(
8279
result.status,
8380
'error',
84-
'🚨 getUserProfile("missing") should return status "error" when fetchUser rejects',
81+
'🚨 getUserProfile("missing") should return status "error"',
8582
)
8683
if (result.status === 'error') {
8784
assert.strictEqual(

exercises/02.async-await/01.problem.linear-flow/README.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ async function loadCookingData() {
2424
}
2525
```
2626

27-
🐨 Open <InlineFile file="index.ts" /> and refactor `loadUserData` so it
28-
uses `async`/`await` instead of `.then()` chains.
27+
🐨 Open <InlineFile file="index.ts" /> and:
28+
29+
1. Refactor `loadUserData` to use `async`/`await` instead of nested `.then()`
30+
2. Keep the same return shape: `{ user, orders }`
31+
3. Await `fetchUser()`, then await `fetchOrders(user.id)`
32+
4. Export `loadUserData`
33+
34+
Completion check: `await loadUserData()` returns Alice (`id: '1'`) and an
35+
orders array whose first order has `userId: '1'`.
2936

3037
📜 [MDN - async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)

0 commit comments

Comments
 (0)