0
0
Typescriptprogramming~10 mins

Tuple with fixed length and types in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a tuple with a fixed length of 2 and types string and number.

Typescript
let user: [string, [1]];
Drag options to blanks, or click blank then click option'
Anumber
Bboolean
Cstring
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using string for both elements instead of number for the second.
Using any which is too general.
2fill in blank
medium

Complete the code to assign values to the tuple with fixed types string and number.

Typescript
user = [[1], 25];
Drag options to blanks, or click blank then click option'
A'Alice'
B25
Ctrue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number or boolean instead of a string for the first element.
Forgetting to use quotes around the string.
3fill in blank
hard

Fix the error in the tuple declaration to ensure fixed length and types string and boolean.

Typescript
let flags: [string, [1]];
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cany
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using string or number instead of boolean.
Using any which is too general.
4fill in blank
hard

Fill both blanks to declare a tuple with fixed length 3 and types number, string, boolean.

Typescript
let data: [[1], [2], boolean];
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of types.
Using any instead of specific types.
5fill in blank
hard

Fill all three blanks to create a tuple with fixed length and types: string, number, boolean.

Typescript
const info: [[1], [2], [3]] = ['John', 30, true];
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using any instead of specific types.
Changing the order of types.