Learn Ruby the Hard Way – Exercise 14 Prompting and Passing

Here is my work for Exercise 14.

Exercise 14 code
Exercise 14 code
Exercise 14 ouput
Exercise 14 input and ouput

Study Drills
1. Find out what Zork and Adventure were. Try to find a copy and play it.
Zork and Adventure was a series of the very first fictional computer games. The first version was written in the late 1970s! That is interesting. Here is Zork I if you want to play.

2. Change the prompt variable to something else entirely.
I changed the prompt to a sentence.

My prompt is
My prompt is “Please type your answer.”

3. Add another argument and use it in your script, the same way you did in the previous exercise with first, second = ARGV.
I changed the first line to user_name, age = ARGV to get a second argument from the command line. I then added the into to the end print.

My inputs and output code. There are 2 arguments on the command line.
My inputs and output code. There are 2 arguments on the command line.

4. Make sure you understand how I combined a """ style multiline string with the #{} format activator as the last print.
The triple-double-quotes are used to enclose a multi-line string. The #{} format activator does string interpolation. The string has one or more placeholders (how many #{} you have within the string). The placeholders are replaced with their corresponding values.  In this exercise, the corresponding values are strings.

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