How do I use an if statement with gets.chomp? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I use an if statement with gets.chomp?

I always get the "wrong answer" https://code.sololearn.com/cY3toiQ4OSSG/?ref=app

14th Aug 2018, 5:23 PM
Yousha
Yousha - avatar
3 Answers
+ 3
Input is a string. You must make it an integer like this: ans = gets.chomp.to_i
14th Aug 2018, 5:44 PM
Paul
Paul - avatar
+ 4
Thanks guys!
14th Aug 2018, 5:53 PM
Yousha
Yousha - avatar
+ 3
The input is converted to a string. Try: if ans == "3" that should fix your problem.
14th Aug 2018, 5:47 PM
Detlef
Detlef - avatar