"The Ternary Operator"


#1

i want to know why my code is wrong:

1 < 2 ? "One is less than two!" : "One is not less than two."

It's interesting for me what will be the difference if I put -

puts 1 < 2 ? "One is less than two!" : "One is not less than two."

or:

1 < 2 ? "One is less than two!" : "One is not less than two."

The program is returning the same result.

Thank you


#2

The reason it is showing output is because it is the last command executed. What you are seeing in the non-puts example is the response of the console. Recommend always use puts or print and don't rely on what you see as actual output.

To experiment,

1 < 2 ? "One is less than two!" : "One is not less than two."
puts

#3

really thank you
It became clear to me


#4

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