If, Else, and Elsif


#1

I’m having a problem with the exercise “If, Else, and Elsif”, which is kinda for consolidating knowledge on the three types of statements. (https://www.codecademy.com/en/courses/learn-ruby/lessons/control-flow-in-ruby/exercises/if-else-and-elsif)

I’ve typed:

puts "Give me a number."
first_number = Integer(gets.chomp)
puts "Give me a second number."
second_number = Integer(gets.chomp)
if first_number > second_number
 print "The first number is greater than the second number"
elsif first number < second number
 print "The first number is less than the second number."
else
 print "Both numbers are equal."
end

Instead of putting the first question out, I get the following response:
(ruby):6: syntax error, unexpected tIDENTIFIER, expecting keyword_do or ‘{’ or ‘(’

I’ve checked my line 6. It seems correct. In no way does the word ‘do’ or ‘{’ or ‘(’ fit into the code. Can anyone tell me what is wrong with my code?


#2

Missing underscores. Looks like four identifiers instead of two.


#3

Thanks so much!! You solved my problem.


#4

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