I want to do something like that.
puts "Please write your age: "
age = gets.chomp
if #{age}<18
puts "you are illegal"
else #{age}>18
puts "You are legal"
end
the output i get is:
"Please write your age" 15. you are illegal you are legal"
and this
"Please write your age 20 you are illegal you are legal"
Why? And what is the solution please?
What I expect is this If I write 19 or older, it will say "you are legal" And if I write 17 or any number below It will tell me "You are illegal"
#{}is used for string interpolation, you don't need it there, and else statements don't work like this (elsifdoes). You also need to convert the string to an integer. You could write it like this:See an article explaining if and else in Ruby