# Learning JavaScript Functions

## Part 1: Functions Background

### Question 1. Fill in the missing word in this statement!

In order for the program to know you are creating a function, it first needs to be defined using a

### Question 2. Fill in the missing word in this statement!

Consider this line of code:

function createThis (  )
{
do something...
}

What is the name given for anything placed in the parentheses after the function name?

### Question 3. Multiple Choice

• The code is the parameters of the function.
• The code is the name of the function.
• This is the code that will be executed when the function is called.

Consider this code:

function myFunction()

{
}

What is the purpose of the code inside the curly braces?

For this question, just select the correct answer!

## Part 2: Functions in depth.

### Question 1. Fill in the missing word in this statement!

Consider this block of code:

function myCalculation(, )
{
return intX * intY;
}

There is something missing for this function perform properly, please enter the missing code in to the blanks.

### Question 2. Multiple Choice.

• The parameters haven't been set correctly.
• There isn't a () operator in the alert statement to call the function return.
• myIntx hasn't been set as a parameter.
• myIntY has no value.

Consider this code below:

function simpleCalc(myIntX, myIntY)
{
return myIntX * myIntX;
}

My result just printed out the definition of the function. Why is that?

### Question 3. Fill in the missing word in this statement!

Consider this code:

function myCalculation(myNumber)
{
return 5+5 +  (myNumber + 10);
}

alert("The result to my calculation is " +
);

//The result
"The result to my calculation is 30"

What would you need to add in to this line of code to allow the result to be correct?

## Overview and Final Assessment

### Question 1: Multiple Choice.

• Result has not been declared as a variable.
• A semi-colon has been placed after the function declaration.
• There is a semi-colon placed after the function declaration and there is no return statement to return value.
• Incorrect spelling for the function name.
• myAddition has been called earlier on in the code before it has been created.

Consider this code:

{
result + 10;
}

When running this code, both an unexpected token error and the result will be undefined.

Why is that?

### Question 2: Fill in the blanks.

Consider this code:

function myCalculation(,)
{
return X - Y;
}

What is missing from this code to perform properly?

### Question 3: Fill in the blanks.

Consider this code:

myCalculation(, parameterY)
{
parameterX * parameterY;
}

Elements are missing from this code block. Fill in the gaps to get this to work properly.

### Question 4. Multiple Choice.

• Misspelling in the function creation.
• There is no return statement in the code execution.
• The alert has not been used to call the function.
• There is a misplaced semi-colon or too many semi-colon's.
• Not enough parameter's declared in the function.
• The curly braces have not been closed.

Uncaught SyntaxError: (Line of code) Unexpected token   ';'

What is this error in reference to?

### Question 5. Fill in the blanks.

Consider this function:

{
}

Although this function would work, what is missing for it to be used.

In order for it to be of any use it needs to be

### Question 6. Fill in the blanks.

What is the name for the brackets used after declaring the function and giving it a name?

What do you place in side these brackets?

### Question 7. Multiple Choice.

• Allows the return statement to return a value.
• A function will give you an error if not used.
• A semi-colon will not work without them.
• The function will return with double the value passed in to it.
• The function definition will only be printed.
• Value cannot be assigned to the parameters without them.

What is the purpose of the () operator when calling a function?

There is more than one potential answer.

### Question 8. Fill in the blanks.

Here we have code that for many reasons won't work. Examine the code and then use the code for fixing blanks to make it a working version.

Broken code:

f1unctions (resultsX, intY);
{
resultsX * resultsY;
}

Code for fixing:

(resultsX, );
{
resultsX * resultsY;
}