Element-ary, My Dear Javascript

[Week 1 - TAAQUI GIPHY] · Lesson 2 · 7 minutes

We start understanding javascript functions and laying the groundwork for our webpage to do what we want it to do, when we want.

As we started discussing last time, functions are sets of instructions written to perform a given action. They're basically recipes. If you follow a set of instructions with baking supplies, at the end you get a cake. It's the same idea - except in this case, we're baking with a programming language and the result is dynamic animations and the validation of data. 

Or, look at it another way: 


We call those ingredients, the things we need to work with, arguments or parameters. They're "passed into" a function the way you would put flour and eggs into a bowl in order to mix them. 

The great thing about functions, as well, is that when you call a function, or order javascript to perform a given function, you can adjust the parameters. In our superAwesomeFudgeCake example, you'd pass in different amounts of eggs and flour to get different sized cakes. 


Tip: Make sure you save the latest version of your project before you refresh and test your work in a browser. Save and check your work often. Whenever you have your code open in a browser, also, make sure you have the inspector open to see exactly what you've done and how it looks. 

So if we go back to our original addEventListener function, we can see that the arguments are the click and the onGoBtnClicked function. Functions can live inside other functions, and work as reactions to things that the user does on the page. 


Ask A Question

Having trouble? Don't worry, you're probably not the only one. Check out the questions other students have or ask yours.