FCC - Finders Keepers

Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). If no element passes the test, return undefined.

by Tom M

HTML

<div id="test">


</div>

JavaScript

function findElement(arr, func) {

var x = arr[3];
if (func(x) == true) {
return x
} else {
return "undefined"
}



}

document.getElementById("test").innerHTML = findElement([2, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; });