Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array of numbers.
DSA Typescript
let numbers: number[] = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which is for objects, not arrays.
Using parentheses () which is for tuples or function calls.
Using angle brackets <> which is for generics, not arrays.
✗ Incorrect
In TypeScript, arrays are declared using square brackets []. So, [1, 2, 3] is the correct way to initialize an array of numbers.
2fill in blank
mediumComplete the code to declare an empty array of strings.
DSA Typescript
let fruits: string[] = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using {} which creates an object, not an array.
Using null or empty string which are not arrays.
✗ Incorrect
An empty array is declared with empty square brackets []. This creates an array ready to hold string elements.
3fill in blank
hardFix the error in the array declaration to hold boolean values.
DSA Typescript
let flags: [1] = [true, false, true];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Boolean[]' which refers to the object wrapper, not the primitive type.
Using 'bool[]' which is not a valid TypeScript type.
✗ Incorrect
In TypeScript, the correct way to declare an array of booleans is boolean[]. 'Boolean[]' is incorrect because Boolean is an object type, not the primitive type.
4fill in blank
hardFill both blanks to declare and initialize an array of numbers with values 10, 20, 30.
DSA Typescript
let scores: [1] = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} to initialize the array which is incorrect.
Mixing declaration styles like 'number[]' with object initialization.
✗ Incorrect
The variable 'scores' is declared as an array of numbers using 'number[]'. The array is initialized with values using square brackets [10, 20, 30].
5fill in blank
hardFill all three blanks to declare a constant array of strings and add a new element.
DSA Typescript
const colors: [1] = ['red', 'green']; colors.[2]('blue'); console.log(colors); // Output: [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'const' and then trying to reassign the array variable instead of modifying it.
Using incorrect method names like 'add' instead of 'push'.
Expecting the output to be a string instead of an array.
✗ Incorrect
The array 'colors' is declared as a string array using 'string[]'. The 'push' method adds 'blue' to the array. The final output shows all three colors in the array.
