#5 open the menu


#1

var main = function() {
$('.icon-menu').click();
}

$(document).ready(main);

In this code it tells me to add a function inside of the click method. I understand the correct answer to that step is this:

$('.icon-menu').click(function() {

}

what i want some clarification on is why i am not typing the name of the function inside of the click method, which is "main" as declared.

this is something that is causing some major confusion. I typically over-analyze everything in life so maybe i am overthinking this but i feel my thought is justified as a noob. I cant understand how typing "function" into the click method does anything because to me "function" is like "variable." If i typed click(variable) or click(parameter) or click(method) they wouldn't do anything, but for some reason im supposed to type click(function) instead of click(main)?

this is the issue i am having the majority of my issues with javascript.


#2

i just talked to myself through this code like a weirdo and i think i might have come to an understanding of it.

I am typing click(function) because i am putting ANOTHER function into the function called main? So there is main = function, and inside of that function is another one nested inside the user input of mouse click?


#3

Hi J,

I am typing click(function) because i am putting ANOTHER function into the function called main?

Yep! That's exactly it :slight_smile:

Taking the JavaScript and jQuery courses (in that order) will also help you understand some of the stuff in this course a little better :slight_smile:

i just talked to myself through this code like a weirdo

That's not weird at all; explaining your code to yourself or someone else, or some nearby object to help you understand it is so common among programmers that it has it's own name: “Rubber Duck Debugging” :slight_smile:


#4

A post was split to a new topic: When I Click menu the screen does not appear


#5

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.