Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to remove the last element from the array.
DSA Javascript
let arr = [1, 2, 3, 4]; arr.[1](); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of pop() adds an element instead of removing.
Using shift() removes the first element, not the last.
✗ Incorrect
The pop() method removes the last element from an array.
2fill in blank
mediumComplete the code to remove the last element and store it in a variable.
DSA Javascript
let fruits = ['apple', 'banana', 'cherry']; let last = fruits.[1](); console.log(last);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which adds elements instead of removing.
Using shift() which removes the first element.
✗ Incorrect
pop() removes and returns the last element of the array.
3fill in blank
hardFix the error in the code to correctly remove the last element.
DSA Javascript
let numbers = [10, 20, 30]; numbers.[1]; console.log(numbers);
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses causes no removal.
Using push() adds elements instead of removing.
✗ Incorrect
pop() must be called as a function with parentheses to remove the last element.
4fill in blank
hardComplete the code to remove the last element and print the updated array.
DSA Javascript
let colors = ['red', 'green', 'blue']; colors.[1](); console.log(colors);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of pop().
Trying to print colors with an incorrect index.
✗ Incorrect
pop() removes the last element; printing colors shows the updated array.
5fill in blank
hardFill both blanks to remove the last element, store it, and print both values.
DSA Javascript
let pets = ['dog', 'cat', 'rabbit']; let removed = pets.[1](); console.log(removed); console.log(pets[2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of pop().
Trying to print pets without length or index.
✗ Incorrect
pop() removes and returns last element; printing removed shows it; printing pets.length shows updated length.
