Weather App - Small problem

hi, I would like some help with this tecnical problem with my pen.
Pen: http://codepen.io/bencarp/pen/qRbKeM/
The code below runs automatically, without the element being clicked.

$('#degrees').click(setTemp());

Please help,
Thanks,
Ben

Answer the following question:

What is the first parameter of click function?
What is the difference between setTemp and setTemp()?
What are you passing to click function?

Hi Gunhoo93,
According to the Jquery documentation (https://api.jquery.com/click/) it is possible to pass the .click function with only a handler/function parameter.
The difference between setTemp and setTemp() is that the first is just the function object. Yet when setTemp is inside an a .click it should only take place when a click event occurs.
If I have a mistake anywhere please point it out.

Ok, thnaks. I was told in the forum that () executes the function no matter where it is. I was somewhat uncomfortable with it because why will something inside an even handler be executed unless the event occurs, but I guess this is how it is in JS. Thanks!

Sorry for the late reply, I was never notified with your reply.
What you mentioned there is not limited to JS, ‘()’ is an operator which calls the function. So, if you used it after function, it will call that function no matter where.

This is what someone else wrote in the chat, and even though I’m a novice I have to somewhat disagree with this statement.
If we have

function a () {
    console.log ('hello world');
}
function b () {
    a(); 
}

To my understanding this should not activate function a.

Sorry man but that’s a syntax error, minimum requirement for non-anonymous function declaration is

function name() {}

function name(); // This is not accepted in JS.

If you were to mean this,

function b() {
    function a() {}
}

What’s the point are you trying to make? Well yea, technically the ‘()’ is after the function name but this isn’t a case where ‘()’ is used as a call operator.

Sorry for not having indentation in the previous post I corrected it.
The communication isn’t going well. The point I tried to make is that not everycase of

function functionName () 

As the code that is inside function b won’t execute function a, unless function b is called.
Thanks for offering your help!

This is getting pedantic and I’ll probably stop after this comment. The indentation isn’t an issue here, the issue is the code below is a syntax error which is not interpreted by JS. What you wrote is unfinished function declaration that has nothing to do with a call operator.

function functionName ();

If your code had a line like that, it won’t even run.

Sorry, I did have a syntax error I take full responsibility for. I meant: a() and not function a()