Does it matter if

Tell us what’s happening:
Does it matter if…I have no idea what the function is doing, other than finding a number in the array that it likes?

Your code so far


function findElement(arr, func) {
let num = 0;
return arr.find(func);
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Finders Keepers

Link to the challenge:

Hey @magopolis,

How do you not understand the function? Didn’t you came up with the method and implemented it yourself? If you really don’t understand.

  • findElement takes 2 parameter
  • Then you declared num = 0, but it’s never used.
  • then you just return a method that takes the arr parameter and then using the .find() method, it will find the elements using the function that is passed using the func parameter.

ok @Catalactics,

I understand the confusion. I mean the (func) argument num => num % 2 === 0
I spent a lot of time sketching out the problems. This is my first challenge with a function as a parameter. Everything I was seeing in the hints told me the function func would solve the problem if i just plug it in. This has been my biggest challenge on this cert- to think analytically and put that mindset in park when problems are solved in the background. like I just figured out console.log("Hello World") doesn’t work unless its defined in the background like this codepen I used the other day for the person[x] you guys were explaining to me.
Knowing how much of what I don’t know is need-to-know for me at present.
Does that make sense?

Yes, it makes sense.

The func argument is just a simple return of a mathematical operator. So if you learned the ES6 already, you know that => is an arrow function that will ALWAYS return if the block is not displayed, like this one. So here’s an explanation:

  • num => - arrow function that takes a parameter and named it num
  • num % 2 - Take num, divide it by 2 then return the remainder.
  • === 0 - If the remainder of num divided by 2 is 0, then return the number taken as true.

not really, just open your browser console with Shift+Ctrl+I, and you have the console where you can see what’s printed
(the console is explained a bit in the debugging section of the curriculum)

the code you have is to make the console.log result appear in the Result panel of the jsfiddle editor

But I imagine that also there you can just open the browser console and see there printed stuff

ok. i understood more than i gave myself credit for. num => I understood. Its hard to google operators and symbols. ! % etc gets mishandled in combo with search termss like JS, CSS, etc. I figured out that % meant remainder but I took it as “remainder = 2”. I couldn’t see why it chose 8…overthinking still but this is progress.

as I stare on blankly (lolz). I understand conceptually what you mean. I dont know what JS Fiddle is. The JS editor used by Codepen.com? in the fork I shared, I could see that it used <html>, but its just an awareness that there is an abyss.

jsfiddle is an other online editor (there are many, more than you can think), the code snippet you have there is so that what would be printed to the browser console is shown in the RESULT box of that editor.
You don’t really need that code snippet, as you can open the browser console and the console.log statements would print there stuff

1 Like