# Finders Keepers Challenge

**URL:** <https://forum.freecodecamp.org/t/finders-keepers-challenge/467274>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 30, 2021, 7:25pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274 "2021-06-30T19:25:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![NathanVu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nathanvu/32/126584_2.png) [@NathanVu](https://forum.freecodecamp.org/u/NathanVu)\
**Post date:** [June 30, 2021, 7:25pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/1 "2021-06-30T19:25:20Z")

</div>

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers)**
>
> Learn to Code — For Free

Hey guys, I already figure out this solution below. I solved it through this way. I was able to print 2 which is the first even number. Also, I’m trying to print 4 as well since it’s an even number. Not sure why it’s just returning 2 only. What am I missing here?

```auto
function findElement(arr, func) {
  let num = 0;
  for ( let i = 0; i < arr.length; i++){
    if(func(arr[i]) === true){
      return arr[i];
    }
  }
  
}

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

```

---

<div class="post-metadata">

**Author:** ![jsdisco](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jsdisco/32/179655_2.png) [@jsdisco](https://forum.freecodecamp.org/u/jsdisco)\
**Post date:** [June 30, 2021, 7:35pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/2 "2021-06-30T19:35:43Z")

</div>

A `return` statement terminates a function. The first time that your condition is true, the loop stops.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [June 30, 2021, 7:42pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/3 "2021-06-30T19:42:41Z")

</div>

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.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

I also added spoiler tags since you code is a solution.

---

<div class="post-metadata">

**Author:** ![NathanVu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nathanvu/32/126584_2.png) [@NathanVu](https://forum.freecodecamp.org/u/NathanVu)\
**Post date:** [June 30, 2021, 7:45pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/4 "2021-06-30T19:45:25Z")

</div>

Okay, it actually works once I remove the return statement and just console.log(arr[i]) it. Thanks. How would I be able to return 2 and 4 without it not terminating right at 2?

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [June 30, 2021, 7:49pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/5 "2021-06-30T19:49:08Z")

</div>

If you want to return multiple things, you need to have a way to store multiple things. What data structure do you know that stores multiple things?

---

<div class="post-metadata">

**Author:** ![NathanVu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nathanvu/32/126584_2.png) [@NathanVu](https://forum.freecodecamp.org/u/NathanVu)\
**Post date:** [June 30, 2021, 8:04pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/6 "2021-06-30T20:04:29Z")

</div>

I guess Arrays, I’m thinking?

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [June 30, 2021, 8:06pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/7 "2021-06-30T20:06:06Z")

</div>

Yep. I would need to put everything you want to return into an array and return that array.

---

<div class="post-metadata">

**Author:** ![NathanVu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nathanvu/32/126584_2.png) [@NathanVu](https://forum.freecodecamp.org/u/NathanVu)\
**Post date:** [June 30, 2021, 8:08pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/8 "2021-06-30T20:08:50Z")

</div>

Oh okay, can I just declare a variable with an empty array, and then push arr[i] into it, and return it?

---

<div class="post-metadata">

**Author:** ![NathanVu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nathanvu/32/126584_2.png) [@NathanVu](https://forum.freecodecamp.org/u/NathanVu)\
**Post date:** [June 30, 2021, 8:12pm UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/9 "2021-06-30T20:12:47Z")

</div>

Hey Jeremy, it works!!! Thank you so much for the input!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [December 30, 2021, 8:13am UTC](https://forum.freecodecamp.org/t/finders-keepers-challenge/467274/10 "2021-12-30T08:13:11Z")

</div>

Closed on December 30, 2021, 8:13am UTC

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