Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

I really need your help with this ruby project

Hi, Jason said at the end of the first level of the ruby project to practice making a questionnaire app. So, I made this

def app(n, b, c) puts "What is your name?" puts "What is your age?" puts "What is you favorite book?" end

app("Enter your name", "Enter your age", "Enter your favorite book")

However, the questions appear in the console, but not Enter your name", "Enter your age", "Enter your favorite book, Would this anyways count as a questionnaire or if not, could someone write the code to make it as I would very much appreciate it

2 Answers

Tim Knight
Tim Knight
28,888 Points

Aaron, consider something like this:

puts "What is your name?\n"
name = gets.chomp
puts "What is your age?\n"
age = gets.chomp
puts "What is your favorite book?\n"
book = gets.chomp

puts "Thank you #{name}, your age is #{age} and your favorite book is #{book}."

You don't necessarily need to put things in a method called app in this case since you're just looking for input from the users at the console. Each time you ask for gets.chomp you're getting the input from the user at the console and setting it to a variable.

1codechic
1codechic
9,399 Points

Hi Aaron,

In order for your user's to be "prompted" for input, you must use the "print" command. See below:

 print "What is your name? "
 name = gets.chomp

 print "What is your age? "
 age = gets.chomp.to_i

 print "What is your favorite book? "
 book = gets.chomp

puts "Thank you #{name}, your age is #{age}, and you favorite book is #{book}."

            ```