JAVA SCRIPT
I am not sure if it works properly, I passed all the test and like the console gives what it asks, but i think i am lost somewhere because i completed it so fast? tell me please
Your code so far
function findElement(arr, func){
for (let i = 0; i < arr.length; i++){
let x = arr[i];
if (func(x) == true){
return x;
}
else if (func(x) == true){
return undefined
}
}
};
console.log(findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; }));
console.log(findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; }));
console.log(findElement([1, 2, 3, 4], function(num) { return num > 2; }));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Build a First Element Finder - Build a First Element Finder
yes? i can see it executed, or am i just lost and the answer is just “undefined” and no matter do i have second if or not? Thats actually why am i asking for, i cant understand why does my code works perfectly, with that type of strange things
because when you have an if followed by an else if, the first one with the true condition will execute, and they are both true or both false, so the else if never executes
but i still cannot get how to put a return for the function, if my function argument is not static, im just lost, already surfing the web for maybe any help, nothing..