Lesson 6 of 40
Lesson Progress: 0%
const numbers = [1, 2, 3, 4, 5, 6];
const evens = numbers.filter(num => num % 2 === 0);
console.log(evens);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
filter() tool goes through your list and asks every number a "Yes" or "No" question.num => part sets up a test that each number must take to see if it can stay.=> arrow points to the secret rule that decides which items are special enough to be kept.const nums = [3, 12, 7, 25, 9];
const small = nums.filter(num => num < 10);
console.log(small);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
filter() tool acts like a security guard that only lets certain numbers into the "VIP" list.num => part tells the computer to pick up each number one by one to check its size.=> arrow points to your test, which in this case is checking if the number is smaller than 10.const names = ["Alice", "Bob", "Andrew", "Cara"];
const aNames = names.filter(name => name.startsWith("A"));
console.log(aNames);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
filter() tool looks at every name in your list to see if it matches your special search rule.name => part tells the computer to grab one name at a time so it can look at the first letter.=> arrow points to the startsWith("A") test, which only says "Yes" to names beginning with a capital A.const people = [
{ name: "Tom", age: 16 },
{ name: "Sara", age: 21 },
{ name: "Mike", age: 18 }
];
const adults = people.filter(person => person.age >= 18);
console.log(adults);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
filter() tool looks inside every person's folder in your list to check if they are old enough to be included.person => part tells the computer to grab one person's information at a time so it can check their age.=> arrow points to your rule, which checks if the age number is 18 or even higher.const words = ["hello", "", "world", "", "JS"];
const filled = words.filter(word => word !== "");
console.log(filled);Instructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
filter() tool goes through your list of words and checks if any of them are empty or "blank."word => part tells the computer to pick up each word one at a time so it can inspect it.=> arrow points to the rule that says "only keep this word if it is NOT empty."Test Incomplete