Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the first element from the array.
DSA Javascript
let arr = [1, 2, 3, 4]; arr.[1](); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes the last element, not the first.
Using push() adds elements instead of removing.
✗ Incorrect
The shift() method removes the first element from an array.
2fill in blank
mediumComplete the code to remove the first element and store it in a variable.
DSA Javascript
let arr = ['a', 'b', 'c']; let first = arr.[1](); console.log(first);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() returns the last element, not the first.
Using slice() does not modify the original array.
✗ Incorrect
shift() removes and returns the first element of the array.
3fill in blank
hardFix the error in the code to correctly remove the first element.
DSA Javascript
let numbers = [10, 20, 30]; numbers.[1](0, 1); console.log(numbers);
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice() expecting it to remove elements modifies nothing.
Using pop() removes the last element, not the first.
✗ Incorrect
splice(0, 1) removes one element starting at index 0, effectively removing the first element.
4fill in blank
hardFill both blanks to remove the first element and print the updated array.
DSA Javascript
let fruits = ['apple', 'banana', 'cherry']; fruits.[1](); console.[2](fruits);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes the last element, not the first.
Using console.print() is not a valid JavaScript method.
✗ Incorrect
shift() removes the first element; console.log() prints the array.
5fill in blank
hardFill all three blanks to remove the first element, store it, and print both values.
DSA Javascript
let colors = ['red', 'green', 'blue']; let removed = colors.[1](); console.[2](removed); console.[3](colors);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes the last element, not the first.
Using console.print() instead of console.log().
✗ Incorrect
shift() removes and returns the first element; console.log() prints values.
