Basic Algorithm Scripting - Finders Keepers

Tell us what’s happening:
Describe your issue in detail here.
I can’t understand why is my code not working?

  **Your code so far**

function findElement(arr, func) {
let num = 0;
for(let i =0; i < arr.length; i++){ 
  num = arr[i];
    // console.log(func(num))
    if(func(num)=== 1){
      return ;
    } else{
      return undefined;
  return num;

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/ Safari/537.36

Challenge: Basic Algorithm Scripting - Finders Keepers

Link to the challenge:

This looks suspicious. What are you supposed to return?

Why check that the return value of the callback is strictly equal to 1?

A return statement inside of a loop immediately stops the loop.

1 Like

Thanks, the code has been fixed after your help :grinning:

1 Like

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