Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array of numbers using generic syntax.
Typescript
let numbers: Array<[1]> = [1, 2, 3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' or 'boolean' instead of 'number' for the array type.
✗ Incorrect
The generic array syntax uses Array<Type>. Here, number specifies the array holds numbers.
2fill in blank
mediumComplete the code to declare an array of strings using generic syntax.
Typescript
const fruits: Array<[1]> = ['apple', 'banana', 'cherry'];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'number' or 'object' instead of 'string' for the array type.
✗ Incorrect
The array holds strings, so the generic type should be string.
3fill in blank
hardFix the error in the generic array declaration.
Typescript
let flags: Array[1] = [true, false, true]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of angle brackets.
✗ Incorrect
The correct generic syntax uses angle brackets: Array<boolean>.
4fill in blank
hardFill both blanks to declare an array of objects with a generic type.
Typescript
const users: Array<[1]> = [[2]];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string type instead of an object type for the generic.
Putting the object type inside the array instead of an object instance.
✗ Incorrect
The generic type defines the shape of objects in the array. The array contains objects matching that shape.
5fill in blank
hardFill all three blanks to declare and initialize a generic array of booleans.
Typescript
let flags: Array<[1]> = [[2], [3]];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' as the generic type.
Using non-boolean values inside the array.
✗ Incorrect
The generic type is boolean. The array contains boolean values true and false.