Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Treehouse Club - MASH MASH - JavaScript Handle Submission and Event Handler Functions

Marilou Lekanne Vaquer
PLUS
Marilou Lekanne Vaquer
Courses Plus Student 1,181 Points

i don't fully understand what it means to 'call a function' . For example with : function random_number (num).

I understand that the function is like engineering the accelerator and calling the function is telling the program on how to use it (pressing the accelerator with your foot). However, in the example of random number, wouldn't you have to put in all possible answers when 'calling the function' ?? That would be a lot of numbers, so that's obviously not correct, but I don't understand how giving for ex the value (46) would be considered calling this function and have it perform the way it should.

1 Answer

tl:dr; Try to separate in your mind the name of a thing, and the thing itself.

imagine you have a button to start your car. but before that button can be pushed, you have to have the key inside the car. that function would look something like this.

function aPushButtonIngnitionCar (wirelessKey) {
   //all the code that makes the ingnition work
}

Where wirelessKey is at, that is something we require to run the function. it refuses to let you push the button otherwise. the actually name in the parentheses doesn't matter. I could have put bunny rabbit. the point is, SOME kind of value must be present to proceed. or else, the button won't push, because the car requires SOMETHING (also known as a parameter) before it can run. SOME kind of key is required for each ingnition sequence.

Now lets look at the random number. random number requires a parameter of num. Now, that's just a handy label so we can reference that parameter in the function itself if we need to. but it could say bubbleFruitsZappyZap and we would still need it. But that isn't very helpful of a name, is it? the num is used to give you a clue that a number is desired. for every time you push the random_number button, you have to first provide a num, or, as the name suggests, a number.

function random_number (num) {
   //insert your logic to be executed here
}

hope that helps some. ask more questions if you need.

Marilou Lekanne Vaquer
Marilou Lekanne Vaquer
Courses Plus Student 1,181 Points

thank you so much Joseph for your time and explanation. It certainly makes more sense now.