Bug or something on Zen of Ruby 4/20 "One Good Turn deserves a Ternary."


#1

I'm going through this exercise and something funny is happening on this one. I can't tell if it's codeacademy, or I'm not getting something. Here's my code:

cheese==true
puts cheese ? "Cheese is good" : "Cheese is bad"

puts true ? "True" : "False"

puts 3 < 4 ? "3 is less than four" : "three is not less than four"

The strange part is that the Ruby console evaluates the cheese part of the code as false. No matter what I put, it still evaluates to "Cheese is bad." I'm confused. The other two evaluate correctly.


#2

cheese is undefined. For it to work it should be "cheese". In quotes.


#3

I'm back at Control Flow: 5/17 Unless - here's the sample code:

hungry = false

unless hungry
puts "I'm writing Ruby programs!"
else
puts "Time to eat!"
end


#4

When you type
cheese == true
you're asking if cheese is true. Remember == is a comparison symbol, like < ,>, <=, and >=.

What you want to do is assert that cheese is true by assigning it's value as true with a single = symbol.

So, instead of asking, "is cheese true?" in the first line, you need to tell Ruby that cheese is true like this

cheese = true