Finders keepers please

Tell us what’s happening:
Describe your issue in detail here.
what am i missing here?

  **Your code so far**

function findElement(arr, func) {
for (let i = 0; i < arr.length; i++){
  if (arr[i] % 2 === 0){
    return arr[i]
  }
}
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/101.0.4951.54 Safari/537.36 Edg/101.0.1210.39

Challenge: Finders Keepers

Link to the challenge:

Are you using func in your code?

yeahh. i even modified my code to be similar to the solution but it seems like im stilll missing something

What is your updated code

function findElement(arr, func) {

  for (let i = 0; i < arr.length; i++){

    if (func(arr[i])){

      return arr[i];

    }

  }

  return "undefined";

}

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

my bad “undefined” != undefined

undefined is a primitive value. You’re returning a string "undefined".

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

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