Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Javascript
class Node { constructor(value) { this.value = [1]; this.next = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name like 'val' or 'node' instead of 'value'.
✗ Incorrect
The constructor parameter is named 'value', so we assign it to this.value.
2fill in blank
mediumComplete the code to set the new node's next pointer to the current head.
DSA Javascript
function push(head, value) {
const newNode = new Node(value);
newNode.next = [1];
return newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to null loses the existing list.
Setting next to value or newNode causes errors.
✗ Incorrect
The new node's next should point to the current head to insert it at the front.
3fill in blank
hardFix the error in the push function to correctly add a new node at the front.
DSA Javascript
function push(head, value) {
const newNode = new Node(value);
newNode.next = [1];
return newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning head instead of newNode causes the list not to update.
✗ Incorrect
The new node's next should point to head, but the function must return newNode to update the list head.
4fill in blank
hardFill both blanks to complete the push function that adds a new node at the front and returns it.
DSA Javascript
function push(head, value) {
const newNode = new Node([1]);
newNode.next = [2];
return newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using null for next loses the existing list.
Using newNode for next causes a cycle.
✗ Incorrect
The new node is created with the given value and its next points to the current head.
5fill in blank
hardFill all three blanks to implement push that creates a new node, links it, and returns it.
DSA Javascript
function push(head, value) {
const newNode = new Node([1]);
newNode.next = [2];
return [3];
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning head instead of newNode.
Setting next to null loses the list.
✗ Incorrect
Create newNode with value, link next to head, and return newNode as new list head.
