Day 4.2 Exercise 21 Functions can return Something

Here’s my work.
Here’s the link to exercise 21.

Ex21 Code
Ex21 Code
Ex21 Shell
Ex21 Output
Ex21a Code
Ex21a Study Code
Ex21a Shell
Ex21a Output

Study Drill

1. If you aren’t really sure what return does, try writing a few of your own functions and have them return some values. You canr eturn anything that you can put to the right of an =.
Understood.

2. At the end of the script is a puzzle, I’m taking the return value of one function and using it as the argument of another function. I’m doing this in a chain so that I’m kind of creating a forumla using the functions. It looks really weird, but if you run the script you can see the results. What you should do is try to figure out the normal formula that would recreate this same set of operations.
Done. Not exactly the same, but I’ve made my own exercise.

3. Once you have the formula worked out for the puzzle, get in there and see what happens when you modify the part of the functions. Try to change it on purpose to make another value.
Done.

4. Do the inverse. Write a simple formula and use the functions to do the same way to calculate it.
So much math….

5. Removed the word return and see if the script still works. You’ll find that it does because Ruby implicitly returns whatever the last expression calculates. However, this isn’t clear so I want you to do it explicitly for my book.
Done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s