Functions as Parameters Help

So I came to the forum again, since I came across another problem that is quite disturbing me. So I’ve been taking the java lessons, and I’ve finally met “Functions as Parameters”. As doing the tasks, I became frustrated since I didn’t quite get it. I found this piece of code in the solution that really turned me upside down.
"const checkConsistentOutput = (func, val) => {
let firstTry = func(val);
let secondTry = func(val);
if (firstTry === secondTry) {
return firstTry
} else {
return ‘This function returned inconsistent results’

checkConsistentOutput(addTwo, 10);"
I got quite confused since I didn’t understand this part “let firstTry = func(val);” also what is this “const checkConsistentOutput = (func, val) => {”
I understand most of the code but I can’t understand what are func and val
And how we do use them. Also here are some screenshots of the tasks and most of the code.

Also sorry for bothering any of you and I’m sorry if my question has already been asked and resolved. I’m new to programming in java and I just want to understand everything as best as I can.

A function is a box that you put something in, and you get some (different thing) out. In practice it’s ideal for what you put in not to be changed.

A camera is a good example. The camera takes in light, and returns you a 2-d image representing the light it received. At no point does the camera actually change the objects that it took the picture of.

A function within a function is the same idea just nested inside of itself. You might have to think a little harder for good real-life analogies.

1 Like