Challenge - 5 Problems
Filter Method Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
What is the output of this filter method?
Look at this JavaScript code. What will it print to the console?
Javascript
const numbers = [1, 2, 3, 4, 5]; const result = numbers.filter(num => num > 3); console.log(result);
Attempts:
2 left
π‘ Hint
Filter keeps only items where the condition is true.
β Incorrect
The filter method keeps numbers greater than 3, so it returns [4, 5].
β Predict Output
intermediate2:00remaining
What does this filter return?
What will be the output of this code snippet?
Javascript
const words = ['apple', 'banana', 'cherry', 'date']; const filtered = words.filter(word => word.length === 5); console.log(filtered);
Attempts:
2 left
π‘ Hint
Check the length of each word carefully.
β Incorrect
Only 'apple' has exactly 5 letters, so the result is ['apple'].
β Predict Output
advanced2:00remaining
What is the output of this filter with objects?
What will this code print to the console?
Javascript
const people = [ {name: 'Alice', age: 25}, {name: 'Bob', age: 17}, {name: 'Carol', age: 19} ]; const adults = people.filter(person => person.age >= 18); console.log(adults);
Attempts:
2 left
π‘ Hint
Filter keeps people who are 18 or older.
β Incorrect
Alice and Carol are 18 or older, so they are included in the result.
β Predict Output
advanced2:00remaining
What happens with this filter callback?
What will this code output?
Javascript
const arr = [0, 1, 2, 3]; const filtered = arr.filter(x => x); console.log(filtered);
Attempts:
2 left
π‘ Hint
Filter keeps items where the callback returns a truthy value.
β Incorrect
0 is falsy, so it is removed. The rest are truthy and kept.
π§ Conceptual
expert2:00remaining
Which option causes a runtime error?
Which of these filter uses will cause a runtime error when run?
Attempts:
2 left
π‘ Hint
Check if the callback tries to access a property on null or undefined.
β Incorrect
Accessing x.length on null or undefined causes a TypeError at runtime.