How do I use gets.chomp for age and same time use if-statements | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

How do I use gets.chomp for age and same time use if-statements

I want to use gets.chomp to find out age, and combine it with if to print out the basic "too young" or above 18, but I just get error when I try to run it. Anyone that gets what I'm missing? https://code.sololearn.com/cfEcU6l0JNns/?ref=app

24th Oct 2018, 5:11 AM
Mattias Mj├Âvik
Mattias Mj├Âvik - avatar
2 Antworten
0
Convert the input to integer with .to_i method on line 2 gets returns a string by default which fails "17" > 18 age = gets.chomp.to_i
24th Oct 2018, 5:19 AM
Lord Krishna
Lord Krishna - avatar
0
Omg, can't belive I missed that xD thank you!
24th Oct 2018, 5:22 AM
Mattias Mj├Âvik
Mattias Mj├Âvik - avatar