If, Else, and Elsif help


#1



https://www.codecademy.com/courses/ruby-beginner-en-NFCZ7/3/2?curriculum_id=5059f8619189a5000201fbcb#

It accepts the code but it's not printing out correctly- it if you imput your name, it should convert to integer then print the correct phase of if statement. Any ideas?


print "what is your name?"
name = gets.chomp.to_i
if name > 5
    print "that's a long name!"
elsif name < 5
    print "That's a short name!"
else 
    print "Good average sized name"
end


#2

Hello :slight_smile:

It looks like you want to get the length of the name. Instead of to_i you have to use length. Take a look:

"maciej".to_i
=> 0
"12".to_i
=> 12

"maciej".length
=> 6
"12".length
=> 2

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.