Deck 19: Programming Functions

Full screen (f)
exit full mode
Question
Functions allow for code to be reused because parts of the solutions are hidden .
Use Space or
up arrow
down arrow
to flip the card.
Question
Variables in the parameter list of a JavaScript function are declared automatically .
Question
The name of a function identifies it and must be used when the function is called .
Question
Function names cannot contain numbers and must not be more than eight characters long .
Question
The return value for a JavaScript function must be a variable .
Question
Local variables cannot be accessed outside the functions in which they are declared .
Question
When calling a function, it does not matter which order you list the arguments .
Question
A variable cannot be used as part of a calculation to assign a value to itself . For example, this JavaScript statement would cause an error, assuming myNum is a numeric variable that has been previously declared and initialized:myNum = myNum*3 + 75/myNum;
Question
A function definition is the same as a function call .
Question
If a function definition contains two parameters, two arguments must be included in the function call .
Question
JavaScript functions can be placed in the <head> section of a web page .
Question
A JavaScript function include at least one parameter .
Question
A computer cannot generate a truly random number .
Question
When two variables have the same name, but one is global and one is local, the JavaScript program will not run .
Question
The arguments in a function call pass values to the parameters, matched in order from left to right .
Question
Programmers rarely use code written by others .
Question
Variables declared within a function

A) cannot be changed in that function
B) can only be used inside the function
C) can be used anywhere in the program
D) can be used outside the function but cannot be changed outside the function
Question
Output directly onto a web page from JavaScript is done using the ________ built-in function .

A) document . display()
B) print()
C) writeln()
D) document . write()
Question
A variable declared in a function is a(n)

A) independent variable
B) named constant
C) local variable
D) global variable
Question
When defining a function that sends a value back to the part of the program that calls it, how do you specify the result?

A) by rewriting it
B) by using the return statement
C) by calling it
D) by designating it as an argument
Question
The inputs to a function are called

A) parameters
B) arguments
C) identifiers
D) values
Question
What, if anything, is wrong with the following JavaScript code?
<script>document . write("<img src = 'puppy . JPG'/>");</script>

A) You cannot use document . write() to display an image; it can only display text .
B) The outer double quotes are not needed with the document . write() function .
C) You cannot use the document . write() function with JavaScript; it must be used with a form .
D) Nothing is wrong with this code .
Question
The values returned by the Math . random()function are between

A) 0 (exclusive) and 1 (exclusive)
B) 0 (inclusive) and 1 (inclusive)
C) 0 (exclusive) and 1 (inclusive)
D) 0 (inclusive) and 1 (exclusive)
Question
The numbers generated by the Math . random()function

A) will never be repeated
B) are random because a computer is deterministic
C) must be multiplied by -1 to change them to positive
D) are pseudo-random
Question
Given the following JavaScript function, which of the following is NOT a possible result?
Function tossIt() {
Return Math . random();
}

A) 0 . 5
B) 0 . 8923871
C) 0
D) 1
Question
If you wanted the following function to return only the two values of 0 and 1, how would you re-write line 2?
1 ) function tossIt() {
2 ) return Math . random();
3 ) }

A) return Math . round();
B) return Math . round(Math . random());
C) return Math . round(random());
D) This cannot be done .
Question
After running the following JavaScript, what is the value of the variable month?
Var newDay = new Date();
Month = newDay . setMonth(4);

A) April
B) June
C) May
D) cannot tell because it depends on what the current date is
Question
Select all that apply . What does the following command do?
Ctx . quadraticCurveTo(20,20,20,50);

A) The curve will end at the point where x = 20 and y = 50
B) The curve will start at the point where x = 20 and y = 20
C) It specifies a curved line .
D) The curve will start at the point where x = 20 and y = 50
Question
Select all that apply . Which of the following are alternate terms for the word 'function'?

A) procedure
B) subroutine
C) method
D) process
Question
Select all that apply . Which of the following are required parts of a function?

A) the local variables
B) the definition
C) the name
D) the parameters
Question
Select all that apply . In JavaScript the result of a function call can be displayed to the user

A) by using an alert()
B) by using the document . write() method
C) by using an absolute reference
D) by using the document . display() method
Question
A function ________ is the algorithm written in a programming language that computes function's result .
Question
A(n) ________ is a programming structure with a name, an optional parameter list, and a definition that encapsulates an algorithm .
Question
Variables declared inside a function are ________ in scope .
Question
When you write code to ask the computer to run or execute the statements in a function, this is referred to as ________ the function .
Question
Functions that are written so they can be reused in other programs are considered ________ .
Question
A function is declared by writing its function ________ .
Question
Date() creates a JavaScript ________ which represents a date and a time .
Question
Joining several components together, as in:
'<tr style="background-color:00ccff ">' + '<td>-10</td><td>' +
convertC2F(-10) + '</td></tr>'
is done using the ________ operator .
Question
The HTML ________ tag provides an area where JavaScript can draw lines and figures .
Question
Other names for a function are ________ or method . Subroutine is an antiquated term for the same thing .
Question
When a function is called, you write the function's name and include any necessary arguments (that is, input values) inside ________ .
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 19: Programming Functions
1
Functions allow for code to be reused because parts of the solutions are hidden .
False
2
Variables in the parameter list of a JavaScript function are declared automatically .
True
3
The name of a function identifies it and must be used when the function is called .
True
4
Function names cannot contain numbers and must not be more than eight characters long .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
The return value for a JavaScript function must be a variable .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
Local variables cannot be accessed outside the functions in which they are declared .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
When calling a function, it does not matter which order you list the arguments .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
A variable cannot be used as part of a calculation to assign a value to itself . For example, this JavaScript statement would cause an error, assuming myNum is a numeric variable that has been previously declared and initialized:myNum = myNum*3 + 75/myNum;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
A function definition is the same as a function call .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
If a function definition contains two parameters, two arguments must be included in the function call .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
JavaScript functions can be placed in the <head> section of a web page .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
A JavaScript function include at least one parameter .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
A computer cannot generate a truly random number .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
When two variables have the same name, but one is global and one is local, the JavaScript program will not run .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
The arguments in a function call pass values to the parameters, matched in order from left to right .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
Programmers rarely use code written by others .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
Variables declared within a function

A) cannot be changed in that function
B) can only be used inside the function
C) can be used anywhere in the program
D) can be used outside the function but cannot be changed outside the function
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
Output directly onto a web page from JavaScript is done using the ________ built-in function .

A) document . display()
B) print()
C) writeln()
D) document . write()
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
A variable declared in a function is a(n)

A) independent variable
B) named constant
C) local variable
D) global variable
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
When defining a function that sends a value back to the part of the program that calls it, how do you specify the result?

A) by rewriting it
B) by using the return statement
C) by calling it
D) by designating it as an argument
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
The inputs to a function are called

A) parameters
B) arguments
C) identifiers
D) values
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
What, if anything, is wrong with the following JavaScript code?
<script>document . write("<img src = 'puppy . JPG'/>");</script>

A) You cannot use document . write() to display an image; it can only display text .
B) The outer double quotes are not needed with the document . write() function .
C) You cannot use the document . write() function with JavaScript; it must be used with a form .
D) Nothing is wrong with this code .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
The values returned by the Math . random()function are between

A) 0 (exclusive) and 1 (exclusive)
B) 0 (inclusive) and 1 (inclusive)
C) 0 (exclusive) and 1 (inclusive)
D) 0 (inclusive) and 1 (exclusive)
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
The numbers generated by the Math . random()function

A) will never be repeated
B) are random because a computer is deterministic
C) must be multiplied by -1 to change them to positive
D) are pseudo-random
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
Given the following JavaScript function, which of the following is NOT a possible result?
Function tossIt() {
Return Math . random();
}

A) 0 . 5
B) 0 . 8923871
C) 0
D) 1
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
If you wanted the following function to return only the two values of 0 and 1, how would you re-write line 2?
1 ) function tossIt() {
2 ) return Math . random();
3 ) }

A) return Math . round();
B) return Math . round(Math . random());
C) return Math . round(random());
D) This cannot be done .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
After running the following JavaScript, what is the value of the variable month?
Var newDay = new Date();
Month = newDay . setMonth(4);

A) April
B) June
C) May
D) cannot tell because it depends on what the current date is
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
Select all that apply . What does the following command do?
Ctx . quadraticCurveTo(20,20,20,50);

A) The curve will end at the point where x = 20 and y = 50
B) The curve will start at the point where x = 20 and y = 20
C) It specifies a curved line .
D) The curve will start at the point where x = 20 and y = 50
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
Select all that apply . Which of the following are alternate terms for the word 'function'?

A) procedure
B) subroutine
C) method
D) process
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
Select all that apply . Which of the following are required parts of a function?

A) the local variables
B) the definition
C) the name
D) the parameters
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
Select all that apply . In JavaScript the result of a function call can be displayed to the user

A) by using an alert()
B) by using the document . write() method
C) by using an absolute reference
D) by using the document . display() method
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
A function ________ is the algorithm written in a programming language that computes function's result .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
A(n) ________ is a programming structure with a name, an optional parameter list, and a definition that encapsulates an algorithm .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
Variables declared inside a function are ________ in scope .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
When you write code to ask the computer to run or execute the statements in a function, this is referred to as ________ the function .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
Functions that are written so they can be reused in other programs are considered ________ .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
A function is declared by writing its function ________ .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
Date() creates a JavaScript ________ which represents a date and a time .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
Joining several components together, as in:
'<tr style="background-color:00ccff ">' + '<td>-10</td><td>' +
convertC2F(-10) + '</td></tr>'
is done using the ________ operator .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
The HTML ________ tag provides an area where JavaScript can draw lines and figures .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Other names for a function are ________ or method . Subroutine is an antiquated term for the same thing .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
When a function is called, you write the function's name and include any necessary arguments (that is, input values) inside ________ .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.