I got all puzzles under functions and I still don't get it

I’m having problems understanding how functions are used especially in the case of returning and recursion. Although I passed all the puzzle in that section I don’t understand it
Someone help me💔


Some codes are run hiddenly so figuring the out maybe abit complicated. Know what youve known and move on .
Alot more will make sense as you progress.

1 Like

@Trillah_Simon Thanks

It calls for keeness mostly.
Anyways you most welcomed swit_zy. :yellow_heart:

1 Like

A function is a piece of code that can be reused even if its given different information.

So for instance if you wanted to add 5 + 5 you can type that in and get an answer. But what if you were given a long list of numbers to add up, thousands of numbers even.

Would you type in each number individually? Or would it be better to use a function?

function addUp (array) {

let sum = 0

for (element of array) {
sum += element
Return sum

So if you were given the list of numbers to add up, probably in a list like an array, then you could just submit it into your function and get the answer. Rather than typing out thousands of numbers.

Return is like pressing = sign on a calculator. If you just typed in 5+5 in a calculator and waited for the answer, you would be waiting a long time. Pressing = returns the answer. Note this doesn’t print it to a console though you still have to print out the answer.

Recursion is when a function calls itself within it’s code block to continue doing something. Acts similar to a loop. So a spell checker wouldn’t correct the first word and then quit, it would continue down the document until the end. It would keep calling itself until none of the ‘error’ words were left and had to be changed.