Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to filter out numbers less than 5 from the array.
Javascript
const numbers = [1, 4, 6, 8]; const filtered = numbers.filter(num => num [1] 5); console.log(filtered);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '<' will keep numbers less than 5, which is the opposite.
Using '===' or '!==' compares equality, not greater or less.
β Incorrect
The filter keeps numbers greater than 5, so we use '>' operator.
2fill in blank
mediumComplete the code to filter only even numbers from the array.
Javascript
const nums = [1, 2, 3, 4, 5]; const evens = nums.filter(n => n [1] 2 === 0); console.log(evens);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '/' divides but does not check remainder.
Using '*' or '+' does not help check even numbers.
β Incorrect
The modulus operator '%' gives the remainder. Even numbers have remainder 0 when divided by 2.
3fill in blank
hardFix the error in the filter callback to keep strings longer than 3 characters.
Javascript
const words = ['cat', 'lion', 'dog', 'elephant']; const longWords = words.filter(word => word.length [1] 3); console.log(longWords);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '<' keeps shorter words, which is wrong here.
Using '===' or '!==' checks equality, not length comparison.
β Incorrect
We want words longer than 3, so use '>' operator to compare length.
4fill in blank
hardFill both blanks to filter numbers divisible by 3 from the array.
Javascript
const arr = [3, 4, 6, 7, 9]; const divisibleByThree = arr.filter(num => num [1] 3 [2] 0); console.log(divisibleByThree);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using '!== 0' keeps numbers not divisible by 3.
Using '>' does not check divisibility.
β Incorrect
Use '%' to get remainder and '===' to check if remainder is zero for divisibility.
5fill in blank
hardFill all three blanks to filter words starting with letter 'a' (case insensitive).
Javascript
const words = ['Apple', 'banana', 'Avocado', 'cherry']; const aWords = words.filter(word => word.[1](0).[2]() [3] 'a'); console.log(aWords);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'toUpperCase' on the whole word instead of the first letter.
Not converting case leads to missing words starting with uppercase 'A'.
β Incorrect
Use 'charAt(0)' to get first letter, then 'toLowerCase()' to compare ignoring case.