# User defined if condition

**URL:** <https://www.ruby-forum.com/t/user-defined-if-condition/188691>\
**Category:** Ruby\
**Created:** [May 16, 2010, 5:35pm UTC](https://www.ruby-forum.com/t/user-defined-if-condition/188691 "2010-05-16T17:35:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 16, 2010, 5:35pm UTC](https://www.ruby-forum.com/t/user-defined-if-condition/188691/1 "2010-05-16T17:35:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 16, 2010, 5:44pm UTC](https://www.ruby-forum.com/t/user-defined-if-condition/188691/2 "2010-05-16T17:44:22Z")

</div>

> puts "what is 2+2 "  
> sorry this is what i ment

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 16, 2010, 6:05pm UTC](https://www.ruby-forum.com/t/user-defined-if-condition/188691/3 "2010-05-16T18:05:55Z")

</div>

On Sun, May 16, 2010 at 10:35 AM, Mark K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## 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/](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

---

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [May 16, 2010, 6:23pm UTC](https://www.ruby-forum.com/t/user-defined-if-condition/188691/4 "2010-05-16T18:23:57Z")

</div>

yhea i did sorry bin at this for hours thanks mate
