Skip to content

Instantly share code, notes, and snippets.

@saterus
Created February 12, 2013 23:06
Show Gist options
  • Save saterus/4774334 to your computer and use it in GitHub Desktop.
Save saterus/4774334 to your computer and use it in GitHub Desktop.
For my ((a family member))'s ((an event)) present about ((a number)) years ago,
I got him a ((gift:a noun)). Not a ((an adjective)) ((gift)) or a loud one or
even a ((an adjective)) ((gift)) that runs around chasing its ((a body part))
and drooling on the ((a noun)). I got them a ((a proper noun)), bred in China
thousands of years ago to be the ((a plural noun)) of the royal family. We
named it ((a proper name)).
@saterus
Copy link
Author

saterus commented Feb 12, 2013

This week's exercise is to write a program that presents the user with Madlibs. The script should ask the user for a series of words, then fill in the proper places in the story using the user's answers.

We'll keep our story format very simple, using a ((...)) notation for placeholders. Here's an example:

Our favorite language is ((a gemstone)).

If your program is fed that template, it should ask you to enter "a gemstone" and then display your version of the story:

Our favorite language is Ruby.

That covers the simple cases, but in some instances we may want to reuse an answer. For that, we'll introduce a way to name them:

Our favorite language is ((gem:a gemstone)). We think ((gem)) is better than ((a gemstone)).

With the above story, your program should ask for two gemstones, then substitute the one designated by ((gem:...)) at ((gem)). That would give results like:

Our favorite language is Ruby. We think Ruby is better than Emerald.

You can choose any interface you like, as long as person can interact with the end result.

Now pair up and try your best to model this with properly decoupled objects sending messages to each other.

TDD will be your friend here. Start with the simplest thing possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment