Finders keepers num and function

Tell us what’s happening:

can someone please help explain why my code doesn’t work. I couldn’t really understand the explanation and the way it used num/function. thank you!

Your code so far


function findElement(arr, func) {

 let num = 0;

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

// return num;
}

console.log(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_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Finders Keepers

Link to the challenge:

  1. Remember that function execution stops as soon as a return statement is reached. Your loop will only check the first value of arr.
  2. You are hardcoding a loop to check for numbers divisible by 2. Your function should use an arbitrary function, passed as the variable func. You are not using func at all in your code.