Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
![](https://videos.teamtreehouse.com/stills/TH-Ruby-LoopsandIterations-Stage3-Video1-stills-4.jpg?token=69972488_b1654f05d3a5d3756baffd46660db1b713cea376)
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Now that we're familiar with loops and iteration, let's practice our knowledge by writing a simple contact list program.
Code Samples
Here is the code we write in this portion of the video.
First, we set up a contact list array:
contact_list = []
Next, we define the ask
method. We're going to be asking the user for input quite a bit so the ask
method will repeat the logic for us.
def ask(question, kind="string")
print question + " "
answer = gets.chomp
answer = answer.to_i if kind == "number"
return answer
end
The ask
method takes two arguments and defaults to having the kind
of answer be a string. This will let us return numeric values if we want.
Finally, we test the ask
method:
answer = ask("What is your name?")
puts answer
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Gennadiy Anikeev
2,559 Points0 Answers
-
Sandra Grassl
6,933 PointsMethods that return a value Code Challenge/Ruby Loops
Posted by Sandra GrasslSandra Grassl
6,933 Points4 Answers
-
John Fisher
7,974 Points11 Answers
-
Thomas Salai
4,964 Points2 Answers
-
Brandon Keene
7,217 Points0 Answers
-
Ali Amirazizi
16,087 Points4 Answers
-
Alec Ortega
12,465 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up