Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
β Incorrect
The map method creates a new array by applying the function to each element.
2fill in blank
mediumComplete 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using filter which removes elements instead of transforming them.
Using sort which changes order but not content.
β Incorrect
map applies the function to each element and returns a new array with uppercase names.
3fill in blank
hardFix 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using + which adds instead of multiplies.
Using - or / which do not double the number.
β Incorrect
To double a number, multiply it by 2 using the * operator.
4fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using + instead of % for checking even numbers.
Using filter instead of map to square numbers.
β Incorrect
Use % to check even numbers and map to square them.
5fill in blank
hardFill 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'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using toLowerCase instead of toUpperCase.
Using filter before map, which would filter original names.
β Incorrect
First map to uppercase, then filter names longer than 3 letters.