Skip to content

Commit 822649d

Browse files
committed
soften hints
1 parent d188ac5 commit 822649d

File tree

36 files changed

+72
-227
lines changed

36 files changed

+72
-227
lines changed

exercises/01.objects/02.problem.property-access/README.mdx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ user['name']
1919
2. Create a function that takes a product object and returns a formatted string
2020
3. Try accessing a property that doesn't exist (see the error!)
2121

22-
💰 Function with object parameter:
23-
24-
```ts
25-
function describe(product: { name: string; price: number }): string {
26-
return `${product.name}: $${product.price}`
27-
}
28-
```
22+
💰 Define a function that accepts an object parameter and builds a string from it.
2923

3024
📜 [MDN - Property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors)

exercises/01.objects/02.problem.property-access/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const product = {
1414

1515
// 🐨 Create a function `formatProduct` that takes a product object
1616
// and returns a string like "TypeScript Handbook - $29.99"
17-
// 💰 function formatProduct(p: { name: string; price: number }): string
17+
// 💰 The function should accept a product object and return a string
1818

1919
// 🐨 Try uncommenting this line - what error do you see?
2020
// console.log(product.rating)

exercises/01.objects/03.problem.object-types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - id: number
66
// - title: string
77
// - completed: boolean
8-
// 💰 type Task = { ... }
8+
// 💰 Define a Task type alias with the listed fields
99

1010
// 🐨 Create a `firstTask` and `secondTask` using the Task type
1111
// - firstTask: id 1, title "Write tests", completed false

exercises/01.objects/04.problem.optional-properties/README.mdx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ const user: UserProfile = {
1919
2. Create users with and without the optional properties
2020
3. Safely access optional properties (check before using!)
2121

22-
💰 Safely accessing optional properties:
23-
24-
```ts
25-
if (user.bio !== undefined) {
26-
console.log(user.bio.toUpperCase()) // Safe!
27-
}
28-
29-
// Or use optional chaining:
30-
console.log(user.bio?.toUpperCase()) // Returns undefined if bio is undefined
31-
```
22+
💰 Check for missing values before using optional properties.
3223

3324
📜 [TypeScript Handbook - Optional Properties](https://www.typescriptlang.org/docs/handbook/2/objects.html#optional-properties)

exercises/01.objects/04.problem.optional-properties/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const bob = {
2323

2424
// 🐨 Create a function that displays user info
2525
// Handle the optional properties safely
26-
// 💰 Use optional chaining: user.bio?.toUpperCase()
27-
// 💰 Or check: if (user.bio !== undefined)
26+
// 💰 Safely handle missing optional values before using them
2827

2928
// function displayUserInfo(user: { ... }): void {
3029
// console.log(`Name: ${user.name}`)

exercises/01.objects/05.problem.dynamic-keys/README.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Dynamic Object Keys
22

33
👨‍💼 We need to model error pages where the property name isn't a valid
4-
identifier (like "404").
4+
identifier (like `status-404`).
55

66
When the property name is stored in a variable, you can use a computed property
77
name in an object literal:
88

99
```ts
10-
const key = '404'
10+
const key = 'status-404'
1111
const errorPages = {
1212
[key]: '/not-found',
1313
}

exercises/01.objects/05.problem.dynamic-keys/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Error Pages
22
// Computed property names in object literals
33

4-
const notFoundKey = '404'
5-
const serverErrorKey = '500'
4+
const notFoundKey = '404-status'
5+
const serverErrorKey = '500-status'
66

77
const notFoundPath = '/not-found'
88
const serverErrorPath = '/server-error'

exercises/01.objects/05.solution.dynamic-keys/README.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Dynamic Object Keys
22

3-
👨‍💼 Nice work! You used computed property names to create keys like "404".
3+
👨‍💼 Nice work! You used computed property names to create keys like "404-status".
44

55
🦉 The key idea is a **computed property name**, which lets you use a variable
66
as the key when creating the object:
77

88
```ts
9-
const key = '404'
9+
const key = 'status-404'
1010
const errorPages = {
1111
[key]: '/not-found',
1212
}

exercises/01.objects/05.solution.dynamic-keys/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ await test('errorPages is exported', () => {
1111

1212
await test('errorPages should include computed keys', () => {
1313
assert.strictEqual(
14-
solution.errorPages['404'],
14+
solution.errorPages['404-status'],
1515
'/not-found',
16-
'🚨 errorPages["404"] should be "/not-found" - use the computed key',
16+
'🚨 errorPages["404-status"] should be "/not-found" - use the computed key',
1717
)
1818
assert.strictEqual(
19-
solution.errorPages['500'],
19+
solution.errorPages['500-status'],
2020
'/server-error',
21-
'🚨 errorPages["500"] should be "/server-error" - use the computed key',
21+
'🚨 errorPages["500-status"] should be "/server-error" - use the computed key',
2222
)
2323
})

exercises/01.objects/05.solution.dynamic-keys/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Error Pages
22
// Computed property names in object literals
33

4-
const notFoundKey = '404'
5-
const serverErrorKey = '500'
4+
const notFoundKey = '404-status'
5+
const serverErrorKey = '500-status'
66

77
const notFoundPath = '/not-found'
88
const serverErrorPath = '/server-error'

0 commit comments

Comments
 (0)