You are on page 1of 2

Unit 7 Lesson 2 Parameters and Return Investigate

Review
● Functions with parameters and return values help us simplify our code
● Functions can only return one value at a time
● A function can have:
○ No parameters and no return values
○ Parameters, but no return values
○ Return values, but no parameters
○ Parameters and return values

Navigate to Level 2 on Code Studio

Level 2 - Follow the instructions, for discussion, add your thoughts here then do the modifications

1. How does calculate() work?

2. What are the arguments passed through the parameter in calculate() when it is called?

3. What types of data does the parameter require in the calculate() function? Where can you find that
information?

4. What is returned? What type of data?

Do This:
● Look at lines 30-36. Look at how the MOD operator % works. Watch the video walk-through about MOD.

Modify: If time allows make these changes to the code

● Add a divide button.


● In addition to displaying if the number is even or odd, display if the number is divisible by 3.

Level 3 - Follow the instructions, for discussion, add your thoughts here then do the modifications
1. Lines 1 - 14: Read the code carefully. What is happening here?

2. Read the function on lines 15-34 carefully. After you are done, explain how the function works,
what parameters it takes and what is returned.

3. How does the Word Game Helper work?

Modify: Extra Time?

● Remove the letter dropbox and replace it with an input box. Update the code so the user
can type any number of letters, and only words that start with those letters and are the
specified length will be displayed.

Takeaways:

Extracting shared features to generalize functionality is known as procedural


abstraction.

Using parameters allows the functions (also called procedures) to be generalized.

Using procedural abstraction helps improve code readability.

Procedural abstraction manages complexity by allowing for code reuse.

● For example: the function move(id, direction) could be used to move an


element in any direction, rather than writing separate functions for each direction.

You might also like