0
0
Javascriptprogramming~10 mins

Array creation 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 create an empty array.

Javascript
const arr = [1];
Drag options to blanks, or click blank then click option'
A()
B{}
C[]
Dnull
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using curly braces {} which create objects, not arrays.
Using parentheses () which are for function calls.
Using null which is not an array.
2fill in blank
medium

Complete the code to create an array with three numbers: 1, 2, and 3.

Javascript
const numbers = [1];
Drag options to blanks, or click blank then click option'
A[1, 2, 3]
B(1, 2, 3)
C{1, 2, 3}
D1, 2, 3
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using curly braces which create objects.
Using parentheses which are for grouping or function calls.
Listing values without brackets.
3fill in blank
hard

Fix the error in the code to create an array with the string 'hello'.

Javascript
const greetings = [1];
Drag options to blanks, or click blank then click option'
A('hello')
B['hello']
C'hello'
D{'hello'}
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using curly braces which create objects.
Using parentheses which do not create arrays.
Using just quotes which create a string, not an array.
4fill in blank
hard

Fill both blanks to create an array of squares for numbers 1 to 5.

Javascript
const squares = Array.from({length: 5}, (_, [1]) => ([2] + 1) * ([2] + 1));
Drag options to blanks, or click blank then click option'
Ai
Bindex
Cn
Dx
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different variable names for the index in the two blanks.
Using the first argument which is the element (undefined here).
5fill in blank
hard

Fill all three blanks to create an array of even numbers from 2 to 10.

Javascript
const evens = Array.from({length: [1], (_, [2]) => ([3] + 1) * 2);
Drag options to blanks, or click blank then click option'
A5
Bi
Cindex
Dn
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong length for the array.
Using the wrong variable name for the index.
Incorrect formula for even numbers.