Parameters CS Thinking Example 1

Follow the full solution, then compare it with the other examples linked below.

Example 1

easy
What is the output of the following? FUNCTION greet(name): OUTPUT 'Hello, ' + name. greet('Alice'). greet('Bob').

Solution

  1. 1
    Step 1: When greet('Alice') is called, the parameter name takes the value 'Alice'.
  2. 2
    Step 2: The function outputs 'Hello, ' + 'Alice' = 'Hello, Alice'.
  3. 3
    Step 3: When greet('Bob') is called, name = 'Bob', so it outputs 'Hello, Bob'. Parameters allow the same function to work with different inputs.

Answer

Hello, Alice then Hello, Bob.
Parameters are variables listed in a function definition that receive values (arguments) when the function is called. They make functions reusable with different data.

About Parameters

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.

Learn more about Parameters โ†’

More Parameters Examples