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

plz someone help me with this gets method

plz listen i want to ask one question to the user and the answer which i shall et from user i want to use it in a string so i asked question and after that maded one variable and putted gets method inside answername variable and after that i printed one statement named "welcome to the programming world ",answername,"Happy Coding" so that name shall be inserted inside the string but the variable answername which contains the value get from the user the string meaning this "welcome to the programming world ",answername i can see in one line but after the answername variable part meaning this "Happy Coding" i can see it in next line but i wanted that part to come on the same line

this is my code :-

def prof print "what is ur name? " answername = gets print "welcome to the programming world ",answername,"Happy Coding" end

prof

plz somone help me plz plz plz

2 Answers

I think I know what you're trying to print. If so, this is how I would do it.

print "Name? "
  name = gets.chomp
puts "Welcome to the programming world, #{name}. Happy coding."

I hope this helps clear some confusion. Also, it was a little hard to read your post. I understand if you have trouble with english.

thanks dude but why u inserted variable inside that string with #{name} the same stuff shall be happened if we just write name

thanks dude but why u inserted variable inside that string with #{name} the same stuff shall be happened if we just write name

If you don't use #{}, it wouldn't insert the captured user input. Instead it would literally print "name", nothing else.

dude i meant to say this

def na print "what is ur name? " name = gets.chomp print "which programming language do u like? " like = gets.chomp print("hello ",name," welcome to the ",like," world") end

na

this way too right na????????

def na print "what is ur name? " name = gets.chomp print "which programming language do u like? " like = gets.chomp print("hello ",name," welcome to the ",like," world") end

No Siddharth, this wouldn't work. Please go back to your Ruby courses to learn why or allow me to explain.