Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array with 3 elements.
DSA Javascript
const arr = [1, 2, [1]];
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number outside the sequence like 4 or 5.
✗ Incorrect
The array is declared with elements 1, 2, and 3.
2fill in blank
mediumComplete the code to create a linked list node with value 10.
DSA Javascript
function Node(value) {
this.value = value;
this.next = [1];
}
const node = new Node(10);Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined or 0 instead of null for the next pointer.
✗ Incorrect
The next pointer of a new node is set to null to indicate the end of the list.
3fill in blank
hardFix the error in the code to link two nodes correctly.
DSA Javascript
const first = new Node(1); const second = new Node(2); first.next = [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning first to first.next causes a cycle.
Using null breaks the link.
✗ Incorrect
The first node's next pointer should point to the second node to link them.
4fill in blank
hardFill both blanks to create an array and a linked list node with value 5.
DSA Javascript
const arr = [[1]]; const node = new Node([2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using different values for array and node.
✗ Incorrect
Both the array and the node hold the value 5.
5fill in blank
hardFill all three blanks to complete the linked list traversal and print values.
DSA Javascript
let current = [1]; while (current !== [2]) { console.log(current.[3]); current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using next instead of value to print.
Looping until current is undefined.
✗ Incorrect
Start from head, loop until current is null, print current.value each step.
