Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Javascript
stack.[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of push removes an element instead of adding.
Using peek only views the top element without adding.
Using shift removes the first element, not related to stack.
✗ Incorrect
The push method adds an element to the top of the stack.
2fill in blank
mediumComplete the code to remove the top element from the stack.
DSA Javascript
const top = stack.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using push adds an element instead of removing.
Using peek only views the top element without removing.
Using unshift adds or removes from the start, not the top.
✗ Incorrect
The pop method removes and returns the top element of the stack.
3fill in blank
hardFix the error in the code to check the top element without removing it.
DSA Javascript
const top = stack.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using pop removes the element instead of just viewing.
Using push adds a new element instead of viewing.
Using shift removes the first element, not the top.
✗ Incorrect
The peek method returns the top element without removing it.
4fill in blank
hardFill both blanks to create a stack and add an element.
DSA Javascript
const stack = new [1](); stack.[2](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Queue instead of Stack changes the data structure.
Using pop instead of push removes an element instead of adding.
✗ Incorrect
We create a new Stack and use push to add an element.
5fill in blank
hardFill all three blanks to remove the top element and check the new top.
DSA Javascript
stack.[1](); const newTop = stack.[2](); console.log(newTop === [3]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of pop adds an element instead of removing.
Using pop instead of peek to view new top removes again.
Comparing to wrong value causes false result.
✗ Incorrect
We remove the top with pop, then check the new top with peek, and compare it to 5.
