0
0
Javascriptprogramming~10 mins

Why arrays are needed in Javascript - Test Your Understanding

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

Complete the code to create an array named fruits.

Javascript
const fruits = [1];
Drag options to blanks, or click blank then click option'
A{'apple', 'banana', 'cherry'}
B'apple', 'banana', 'cherry'
C['apple', 'banana', 'cherry']
D(apple, banana, cherry)
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using curly braces instead of square brackets
Not using any brackets
Using parentheses instead of brackets
2fill in blank
medium

Complete the code to access the first fruit in the array.

Javascript
const firstFruit = fruits[1];
Drag options to blanks, or click blank then click option'
A(0)
B[0]
C{0}
D<0>
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using parentheses instead of square brackets
Using curly braces
Using angle brackets
3fill in blank
hard

Fix the error in the code to add a new fruit to the array.

Javascript
fruits[1]('orange');
Drag options to blanks, or click blank then click option'
Apush
Badd
Cappend
Dinsert
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using add which is not a method
Using append which is not valid in JavaScript
Using insert which does not exist
4fill in blank
hard

Complete the code to create an array of numbers and get the last number.

Javascript
const numbers = [1, 2, 3, 4, 5];
const lastNumber = numbers[numbers[1] - 1];
Drag options to blanks, or click blank then click option'
A[
B]
C.length
D.size
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using .size which is not valid for arrays
Using parentheses instead of square brackets
Not subtracting 1 from length
5fill in blank
hard

Fill both blanks to create an array of words, filter words longer than 3 letters, and create a new array with their lengths.

Javascript
const words = ['cat', 'elephant', 'dog', 'bird'];
const longWordsLengths = words
  .filter(word => word[1] 3)
  .map(word => word[2]);

console.log(longWordsLengths);
Drag options to blanks, or click blank then click option'
A.length >
B.length
C[0]
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using comparison without .length
Trying to access word as an array incorrectly
Not logging the array correctly