Functions Flashcards
What is a function?
It’s a set of instructions,
you want to run over and over again.
How does a function begin?
Let’s look at the structure of a function.

using the function keyword
What is the function name in this example?

[goToCoffeeShop]
What is the function parameter?

(drink)
What role does the curly braces serve?

start and end of function
What is an argument?
An argument is a value (primitive or object)
passed as input to a function.
How do you call a function?
use the function name followed by parenthesis and semi-colon
goToCoffeeShop();
Why use functions?
To avoid unnecessary repetition and effort
To avoid having to re-enter code in multiple places
What does this function do?

It generates a random number between 1 and 6.
In this example, where are the functions in this snippet?

Find by ()
floor is a function
random is a function
Will this code run?

No
The function hasn’t been called
What does the alert(); function do?
It creates a simple pop up window

How do you call a function?
functionName();
Why will this JavaScript run successfully?

The function is being called
What’s the advantage of using functions?
It produces multiple results,
without repeating code.
How is the function being called in this example?

alertRandom();
How do you call a function multiple times in a row?
repeat the function call
In this example, how many times is the function being called?

4 times
When the function is called 4 times, how is the number appearing on the screen?
It’s basically creating 4 popups, one after the other.
Each popup has a randomly generated number.
What is a return?
A return is a function that gives you the value of a variable.
Is return more flexible?
Yes
You can manipulate output as alert, console,
or store a value in a variable.
In this example, why does alert removed and return added?
In the original function, the alert was hardwired into it; this limits its functionality to only one way to output the code.
Why was the function renamed?

It no longer made sense to use alert in
the function name, as it was going to
be capable of more than that.
How do you call a function outcome from an alert?
alert( functionName() );



















































