Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the array.
DSA Typescript
const arr = [10, 20, 30, 40]; const value = arr[[1]]; console.log(value);
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 to access the third element (off by one error).
Using index 4 which is out of bounds.
✗ Incorrect
Index 2 accesses the third element in the array, which is 30.
2fill in blank
mediumComplete the code to update the element at index 1 to 50.
DSA Typescript
const arr = [10, 20, 30]; arr[[1]] = 50; console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Updating index 0 instead of 1.
Using index 3 which is out of bounds.
✗ Incorrect
Index 1 refers to the second element, which is updated to 50.
3fill in blank
hardFix the error in the code to correctly update the last element to 100.
DSA Typescript
const arr = [5, 10, 15]; arr[[1]] = 100; console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 which is out of bounds.
Using negative index which is not valid in TypeScript.
✗ Incorrect
Index 2 is the last element in the array of length 3.
4fill in blank
hardFill both blanks to access and update the element at index 0 to 99.
DSA Typescript
const arr = [1, 2, 3]; arr[[1]] = [2]; console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index like 1 or 3.
Assigning wrong value like 100 instead of 99.
✗ Incorrect
Index 0 accesses the first element, which is updated to 99.
5fill in blank
hardFill all three blanks to double the value at index 2 and update it.
DSA Typescript
const arr = [2, 4, 6]; arr[[1]] = arr[[2]] [3] 2; console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indexes for BLANK_1 and BLANK_2.
Using addition instead of multiplication.
✗ Incorrect
Index 2 accesses the third element; multiplying by 2 doubles it.
