Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an empty array named numbers.
DSA Javascript
const numbers = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which create objects, not arrays.
Using parentheses () which are for function calls.
Assigning null instead of an empty array.
✗ Incorrect
In JavaScript, arrays are declared using square brackets []. So,
const numbers = []; creates an empty array.2fill in blank
mediumComplete the code to create an array fruits with three elements: 'apple', 'banana', and 'cherry'.
DSA Javascript
const fruits = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or curly braces instead of square brackets.
Forgetting commas between elements.
Not putting quotes around string elements.
✗ Incorrect
Arrays in JavaScript are created using square brackets with elements separated by commas.
3fill in blank
hardFix the error in the code to correctly declare an array colors with 'red', 'green', and 'blue'.
DSA Javascript
const colors = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons instead of commas between elements.
Omitting commas between elements.
Using parentheses instead of square brackets.
✗ Incorrect
Array elements must be separated by commas inside square brackets. Semicolons or missing commas cause errors.
4fill in blank
hardFill both blanks to create an array numbers with numbers 1 to 5.
DSA Javascript
const numbers = [1]; console.log(numbers[2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for array declaration.
Using
.size which is not valid for arrays in JavaScript.✗ Incorrect
Arrays are declared with square brackets. To get the number of elements, use the
length property.5fill in blank
hardFill all three blanks to declare an array letters, add 'd', and print the element at index 2 of the updated array.
DSA Javascript
const letters = [1]; letters[2]('d'); console.log(letters[3]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using
pop instead of push to add elements.Trying to access elements with parentheses instead of square brackets.
Forgetting to declare the array with square brackets.
✗ Incorrect
Declare the array with square brackets. Use
push to add an element. Access element at index 2 with [2].