Finders Keepers confusion

I am wondering how the func num=> num % 2 ===0 works? Why the zero at the very end? My last question is how does the return undefined work at its specific location? Why is it placed after two }} and before one }. Thank you!

   **Your code so far**
function findElement(arr, func) {
 let num = 0;
 for (let i =0; i<arr.length; i++){
   num = arr[i]
if(func(num)){
return num
}
 }
 return undefined;
}

console.log(findElement([1, 2, 3, 4], num => num % 2 === 0));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36

Challenge: Finders Keepers

Link to the challenge:

That function says “return true if the remainder of dividing num by 2 is 0”.

Try formatting the code by right clicking the editor and selecting the format option, then you can see where the return statement lines up easier.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.