Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an object with inline type annotation.
Typescript
const user: [1] = { name: "Alice", age: 30 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using array syntax instead of object syntax for the type.
Using primitive types like string or number instead of an object type.
✗ Incorrect
The inline type annotation for an object with properties name (string) and age (number) is { name: string; age: number }.
2fill in blank
mediumComplete the code to annotate an object with optional property.
Typescript
const product: [1] = { id: 101, name: "Book" };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking required properties as optional.
Omitting the question mark for optional properties.
✗ Incorrect
The property price is optional, so it is marked with a question mark (price?: number).
3fill in blank
hardFix the error in the inline object type annotation.
Typescript
const settings: [1] = { darkMode: true, fontSize: 14 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of semicolons between properties.
Using capitalized Boolean or Number types.
✗ Incorrect
In TypeScript, object properties in type annotations are separated by semicolons, not commas.
4fill in blank
hardComplete the code to declare an object with a nested object type inline.
Typescript
const employee: [1] = { name: "John", address: { city: "NY", zip: 10001 } };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of semicolons in object type annotations.
Mixing commas and semicolons inconsistently.
✗ Incorrect
Use semicolons to separate properties in both the outer and nested object types.
5fill in blank
hardFill all three blanks to declare an object with inline type annotation including a method.
Typescript
const calculator: [1] = { add: (a: number, b: number) => a [2] b, subtract: (a: number, b: number) => a [3] b };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names in the type annotation.
Using wrong operators in the method implementations.
Mixing commas and semicolons in type annotations.
✗ Incorrect
The object type annotation declares methods add and subtract with correct parameter names and return types. The add method uses + and subtract uses - operators.