Not understanding what is the required from Finders Keepers challenge

Tell us what’s happening:
I didn’t understand what is this challenge and what should we do?

This is the original code of the challenge below


function findElement(arr, func) {
let num = 0;
return num;
}

findElement([1, 2, 3, 4], num => num % 2 === 0);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0.

Challenge: Finders Keepers

Link to the challenge:

Hey @abdulrahman.mhd.anas!

Whenever you are confused about what the challenge is asking from you it will help to look at the test cases.

In the first test cases we have an array like this [1, 3, 5, 8, 9, 10] and a function as the second argument like this function(num) { return num % 2 === 0; }

Our task is to return the first element in the array that passes this test num % 2 === 0.

So what is the first number in the list that passes the test?
It is 8 right? We can check by substituting num for 8.

8 % 2 === 0

translates to
8 divided by 2 gives us a remainder of 0.

Your job is to create a function that returns the first element in the array that passes the test from the function argument. If none of the elements pass the test then your function needs to return undefined.

Hope that helps!

Tell us what’s happening:
I have completed the half of the challenge. The other half I got stuck of it
What are the mistakes on my code. What is the steps to correct my mistakes and return as below:

findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; });

Your code so far


function findElement(arr) {

for (let num = 0; num < arr.length; num++) {
 if (arr[num] % 2 === 0) {
   return arr[num];
 }
 else {
   return undefined;
 }
}  
}


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0.

Challenge: Finders Keepers

Link to the challenge:

Instead of using the func argument, you seem to have just deleted it. Your current code returns the first array element if it is divisible by 2. Otherwise, it returns undefined.

I add func again but nothing happened!
I still had the same problem

Are you using func or are you still just checking whether the first element in the array is even?

Yes, I 'm just doing that because I don’t where to use func

Ok. Well, that’s why it’s wrong. I recommend reading the instructions again carefully. What is the func argument and what are you told to use it for?