Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert the value 5 at the beginning of the array.
DSA Javascript
let arr = [1, 2, 3]; arr.[1](5); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of unshift(), which adds at the end.
Using pop() or shift(), which remove elements instead of adding.
✗ Incorrect
The unshift() method adds one or more elements to the beginning of an array.
2fill in blank
mediumComplete the code to insert the string 'start' at the beginning of the array.
DSA Javascript
const items = ['middle', 'end']; items.[1]('start'); console.log(items);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which adds at the end, not the beginning.
Using pop() or shift() which remove elements.
✗ Incorrect
unshift() adds the element 'start' at the beginning of the array.
3fill in blank
hardFix the error in the code to correctly insert 10 at the beginning of the array.
DSA Javascript
let numbers = [20, 30, 40]; numbers.[1](10); console.log(numbers);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which adds at the end.
Using pop() or shift() which remove elements.
✗ Incorrect
unshift() correctly inserts 10 at the beginning of the array.
4fill in blank
hardFill both blanks to insert 'first' at the beginning and remove the last element.
DSA Javascript
let arr = ['second', 'third', 'fourth']; arr.[1]('first'); arr.[2](); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() instead of unshift() to add at the start.
Using shift() instead of pop() to remove the last element.
✗ Incorrect
unshift() adds 'first' at the start; pop() removes the last element.
5fill in blank
hardFill all three blanks to insert 0 at the beginning, add 4 at the end, and remove the first element.
DSA Javascript
let nums = [1, 2, 3]; nums.[1](0); nums.[2](4); nums.[3](); console.log(nums);
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up shift() and pop() for removing elements.
Using push() to add at the beginning instead of unshift().
✗ Incorrect
unshift() adds 0 at start; push() adds 4 at end; shift() removes first element.
