0
0
Javascriptprogramming~10 mins

Array length property in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Alength
Bsize
Ccount
Dtotal
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'size' instead of 'length'.
Trying to call length as a function like length().
2fill in blank
medium

Complete 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'
Asize
Btotal
Clength
Dcount
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'size' or 'count' which are not valid array properties.
Forgetting to compare length to 0.
3fill in blank
hard

Fix 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'
Atotal
Bsize
Ccount
Dlength
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses after length causing a TypeError.
Using incorrect property names like size or count.
4fill in blank
hard

Fill 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'
A5
Blength
Csize
D10
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.
5fill in blank
hard

Fill 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'
Apush
Blength
C0
D1
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.