Tell us what’s happening:
This is my work so far and it passed, but it’s kind of a cheat since on line 6 I directly used (num % 2 === 0) as the if statement condition. I tried to change this condition to if (func) or if (func == true) but it would not pass.
I thought (func) would generate the same result as (num % 2 === 0) because it is literally the only code in the func function, but it wouldn’t, and I’m confused why not. Can anyone please explain to me? Thank you very much.
Your code so far
[spoiler]
function findElement(arr, func) {
let x = 0;
for (let i=0; i<arr.length; i++){
let num = arr[i];
console.log(num);
if (num % 2 === 0){
return arr[i];
i = arr.length;
x++;
}
}
if (x == 0){
return undefined;
}
}
findElement([1, 2, 3, 4], num => num % 2 === 0);
[/spoiler]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
.
Link to the challenge: