JavaScript Functions Worksheet

Question 1

What is a function, and why would you ever want to use one in your code?

A function is a task and is useful when repeting that task more than once.
Question 2

What do you call the 'inputs' that get passed into a function?

Parameters
Question 3

Do all functions have return values?

No
Question 4

What is the 'body' of a function, and what are the characters that enclose the body of a function?

The rules of that function and is enclose {}.
Question 5

What does it mean to 'call', or 'invoke' a function (note that 'calling' and 'invoking' a function mean the same thing)?

To use the function.
Question 6

If a function has more than one parameter, what character do you use to separate those parameters?

A comma.
Question 7

What is the problem with this code (explain the syntax error)?


function convertKilometersToMiles(km)
    return km * 0.6217;
}
                

There should be a var line before the return, var line should have miles= km * 0.6217

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.