Console.log inside a function

Hi everyone

I have a question about how to use console.log inside a function. My idea is to be able to log the results by calling the function directly, without having to use console.log each time I want to use the function.

So far I have this

As you can see, I set the console.log within the function clamp1, but when I try to call the function, it doesn’t log anything.

However, when I do this, the console.log works:

I don’t understand why I can’t use the console.log inside the function.

Thank you so much for your help!

makes no difference
but you would need to execute that line, having it in your code isn’t enough, program control has to reach it

if (false) {
    console.log('this does not print anything')
}

What happens when a return statement is reached?

Now apply that knowledge in finding out how nothing is logged in your first iteration.

1 Like

Thank you for that now makes sense!! Working fine :grinning: :grinning:

What is your code now?

This is what it looks like now:

Now the console functions executes within the function.

1 Like

There you go, but I suggest you also look in to indentations and use of syntax. There is one thing off now.