1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Parameters
Inputs to a function (located inside parenthesis)
Example of a parameter
function doubleNumber(x){ ; The parameter here is x.
Scope
The part of the program where the variable exists
Local Variable
A variable that can only be used within the functions that define them.
Global Variable
A variable that can be used throughout a program in every scope.
Example of Local Variables
function myFunction(x){
let doubleX=x*2;
return doubleX;
}
The local variable would be doubleX and x because they are defined within the function
Why do we write functions?
They make our code easier to understand by giving a readable name to a group of instructions, they help us avoid writing repeated code, and make our code reusable.
What is the parameter of the function quardrupleNumber?
function quadrupleNumber(x){
var quadX=4*x;
println(quadX);
}
x
What is the output of the following code?
function start(){
var x=5;
quadruplesNumber(x);
}
function quadrupleNumber(x){
var quadX=4*x;
println(quadX);
}
20
What are the parameters of the printNumbers function?
function printNumbers(first, second, third){
println(first);
println(second);
println(third);
}
first, second, third
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);
}
4
5
6
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(40, Color.blue, 300, 400);
Do functions need to have parameters?
No
Which statements allows us to return values from functions?
return
What is printed when the following code is run?
function doubleNumber(x){
return 2*x;
} f
unction start(){
var y = 4;
var doubledY = doubleNumber(y);
var result = doubleNumber(doubledY);
print(result);
}
16
How many parameters go into the function sum?
function sum(first, second){
var result = first + second;
return result;
}
2
How many return values come out of the function sum?
function sum(first, second){
var result = first + second; return result;
}
1