Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Created December 2, 2014 21:21
Show Gist options
  • Select an option

  • Save vanderhoop/402c44d8f1fb08d0f220 to your computer and use it in GitHub Desktop.

Select an option

Save vanderhoop/402c44d8f1fb08d0f220 to your computer and use it in GitHub Desktop.

While The Cradle Rocks

In today's "student" directory, write a short Ruby program that tracks all the things Phil does while his son, Jim-Kevin, sleeps.

Directions

  1. Create a Ruby file, while_the_cradle_rocks.rb within today's "student" directory.
  2. Within while_the_cradle_rocks.rb, create a variable, jim_kevin_is_sleeping and assign it the Boolean value of true
  3. Create a variable, phils_accomplishments and assign it an empty string ""
  4. Create a while loop that will run as long as Jim-Kevin is sleeping.
  5. As long as Jim-Kevin sleeps, ask Phil what errand he runs. Use string concatenation to add it to the end of the phils_accomplishments string, along with a comma and a space, as this should print as a string.
  6. Just before the end of the while loop, ask Phil if Jim-Kevin is still sleeping. Depending on her answer, assign jim_kevin_is_sleeping to either true or false.
  7. After Jim-Kevin wakes up, print the value of phils_accomplishments to the console.

Bonus

Make it print in a sensible manner.

Example: While the Cradle Rocked, Phil built up his knowledge in Ruby, took a nap himself, and went to the corner grocery.

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