0
0
Javascriptprogramming~10 mins

Map method 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 a new array with each number doubled using the map method.

Javascript
const numbers = [1, 2, 3];
const doubled = numbers.[1](num => num * 2);
console.log(doubled);
Drag options to blanks, or click blank then click option'
Afilter
Bmap
CforEach
Dreduce
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using forEach instead of map, which does not return a new array.
Using filter, which only selects elements but does not transform them.
2fill in blank
medium

Complete the code to convert all names in the array to uppercase using map.

Javascript
const names = ['alice', 'bob', 'carol'];
const upperNames = names.[1](name => name.toUpperCase());
console.log(upperNames);
Drag options to blanks, or click blank then click option'
Afilter
Bsort
Cmap
Dslice
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using filter which removes elements instead of transforming them.
Using sort which changes order but not content.
3fill in blank
hard

Fix the error in the code to correctly double each number using map.

Javascript
const nums = [4, 5, 6];
const doubled = nums.map(num => num [1] 2);
console.log(doubled);
Drag options to blanks, or click blank then click option'
A*
B/
C-
D+
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using + which adds instead of multiplies.
Using - or / which do not double the number.
4fill in blank
hard

Fill both blanks to create an array of squares of even numbers only.

Javascript
const nums = [1, 2, 3, 4, 5];
const squares = nums.filter(n => n [1] 2 === 0).[2](n => n * n);
console.log(squares);
Drag options to blanks, or click blank then click option'
A%
Bmap
Cfilter
D+
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using + instead of % for checking even numbers.
Using filter instead of map to square numbers.
5fill in blank
hard

Fill all three blanks to create an array of uppercase names longer than 3 letters.

Javascript
const names = ['Ann', 'Beth', 'Cara', 'Dan'];
const result = names.[1](name => name.[2]()).[3](name => name.length > 3);
console.log(result);
Drag options to blanks, or click blank then click option'
Amap
BtoUpperCase
Cfilter
DtoLowerCase
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using toLowerCase instead of toUpperCase.
Using filter before map, which would filter original names.