5.1.2 Functions And Parameters Quiz 1

Question: What is the output of the following code?

function start(){

var x = 5;

quadrupleNumber(x);

}

function quadrupleNumber(x){

var quadX = 4 * x;

println(quadX);

}

10

15

20

no output, there is a syntax error

Answer: 20

Question: function quadrupleNumber(x){

var quadX = 4 * x;

println(quadX);

}

What is the parameter of the function quadrupleNumber?

x

println

quadX

none

Answer: x

Question: Why do we write functions?

Make our code easier to understand by giving a readable name to a group of instructions

Avoid writing repeated code

Make our code reusable

All of the above

Answer: All of the above

Question: What are the parameters of the printNumbers function?

function printNumbers(first, second, third){

println(first);

println(second);

println(third);

}

first, second, third

x, y, z

println

printNumbers

Answer: first, second, and third

Question: What is printed by the following code?

function printNumbers(first, second, third){

println(first);

println(second);

println(third);

}

function start(){

var middle = 5;

printNumbers(4, middle, 6);

}

456

4

5

6

4middle6

4

middle

6

Answer: 4

5

6

Question: If we want to draw a circle using our helpful drawCircle function at position (300, 400) with a radius of 40 and color blue, which is the correct function call?

As a reminder, here’s the function header for drawCircle:

function drawCircle(radius, color, x, y)

drawCircle(300, 400, 40, Color.blue);

drawCircle(300, 400, Color.blue, 40);

drawCircle(40, Color.blue, 300, 400);

drawCircle(radius, color, x, y);

Answer: drawCircle(40, Color.blue, 300, 400);

Question: Do functions need to have parameters?

yes

no

Answer: no

Question: What is printed when the following code is run?

function doubleNumber(x){

return 2*x;

}

function start(){

var y = 4;

var doubledY = doubleNumber(y);

var result = doubleNumber(doubledY);

print(result);

}

4

8

16

64

Answer: 16

Question: Which statement allows us to return values from functions?

break

return

if

function

Answer: return

Question: How many parameters go into the function sum?

function sum(first, second){

var result = first + second;

return result;

}

1

0

3

2

Answer: 2

Donation Page

Support Our Work

Do you appreciate the value this website provides? If so, please consider donating to help keep it running. Your donation will go a long way in helping us continue to provide the same quality of content and services. Every bit helps, and your support is greatly appreciated. Thank you for your generosity.