I know the solution has a more concise code but I don’t understand why the code I wrote doesn’t work? What am I missing?
Also - I don’t understand why the solution doesn’t return all values in the array that pass the truth test (as it is using a for loop). The challenge asks for just the first one.
The above sets the value of arr[i] to true and then func is called passing the value true to it. I am sure this is not what you want to do.
2nd issue (assuming you fix the above statement) is that your function will only look at the first element in arr before returning the value 1 (the first element in arr) or undefined.
Remember when a return statement is executed, the function immediately exits. Think about when/where you should really use the return undefined statement.
remember that when you have an else statement at the end, one of the statements in the chain will always execute - you have a return statement inside the loop and a return statement will break from the function returning a value, you have a return undefined that will run as soon as the if condition is false
remember that func(arr[i]) returns a boolean, so you may want to compare it with true or false not with a number