From: Josh Cheek Date: 2010-05-17T01:05:14+09:00 Subject: Re: user defined if condition --0016e6d77d12d71eab0486b845b9 Content-Type: text/plain; charset=ISO-8859-1 On Sun, May 16, 2010 at 10:35 AM, Mark Kirby wrote: > hi iv just started to learn ruby 2 days ago and have no programing exp > so sorry if this is a stupid question > > what i want to do is have some thing happen depending on the exact word > or number the user imputs hears an exampel > > puts "what is 2=2 " > input=gets > if > #the user presses 2 then > puts "correct" > else > puts "wrong" > what would i put in the # section or is it more complicated than this > thanks > -- > Posted via http://www.ruby-forum.com/. > > Having a little bit of difficulty following, I assume you meant "if the user *enters* *4*, then tell them they did it correctly". In which case you could have it like this: print "2 + 2 = " input = gets.chomp # chomp removes the newline from pressing the enter key if input == '4' # remember input comes in as a String, so we compare to String representation of 4 puts 'correct' else puts 'wrong' end --0016e6d77d12d71eab0486b845b9--