Finders Keepers Bug

My code:

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';

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

With the above code, the following criteria for the exercise is not met: “findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })` should return undefined”

However when i run the function with that array and log the results to the console it does in fact return undefined.

Bug in the exercise??

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.

Link to the challenge:

Remove the quotes around ‘undefined’.

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 easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


Ah ok I skimmed over that part. Thanks for editing.

Yep, that works. Thanks!!