Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the length of the array.
Javascript
const fruits = ['apple', 'banana', 'cherry']; console.log(fruits.[1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'size' instead of 'length'.
Trying to call length as a function like length().
β Incorrect
The length property returns the number of elements in an array.
2fill in blank
mediumComplete the code to check if the array is empty.
Javascript
const numbers = []; if (numbers.[1] === 0) { console.log('Array is empty'); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'size' or 'count' which are not valid array properties.
Forgetting to compare length to 0.
β Incorrect
Checking if length is 0 tells us if the array has no elements.
3fill in blank
hardFix the error in accessing the array length.
Javascript
const colors = ['red', 'green', 'blue']; console.log(colors.[1]());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using parentheses after length causing a TypeError.
Using incorrect property names like size or count.
β Incorrect
length is a property, not a function, so it should not have parentheses.
4fill in blank
hardFill both blanks to create an array of numbers and print its length.
Javascript
const numbers = new Array([1]); console.log(numbers.[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'size' instead of 'length' for the property.
Using a string instead of a number for the array size.
β Incorrect
new Array(5) creates an array with length 5, and length property gives the size.
5fill in blank
hardFill all three blanks to create an array, add an element, and print the new length.
Javascript
const arr = []; arr.[1]('hello'); console.log(arr.[2] + [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using incorrect method names like 'add' instead of 'push'.
Trying to call length as a function.
Adding 0 instead of 1 to length.
β Incorrect
push adds an element, length gives current size, adding 1 gives the new length after adding the element.