Practice Parameters in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
Named values declared in a function definition that act as placeholders for the actual data (arguments) passed in when the function is called. Parameters allow the same function to operate on different data each time it is invoked.
The blanks you fill in when using a function. Like a form with fields.
Example 1
easyWhat is the output of the following? FUNCTION greet(name): OUTPUT 'Hello, ' + name. greet('Alice'). greet('Bob').
Example 2
mediumFUNCTION calculateArea(length, width): RETURN length * width. What is calculateArea(5, 3)? What happens if you call calculateArea(5) with only one argument?
Example 3
mediumWrite a function called power(base, exponent) that returns base raised to the exponent using a loop. Trace power(2, 4).
Example 4
hardExplain the difference between passing by value and passing by reference. If FUNCTION double(x): x = x * 2 is called with SET a = 5. double(a), what is the value of a after the call in each case?