Unless in control flow in ruby


#1

UNLESS in ruby control flow

these are the instructions.

                  * We've started you off in the editor. Replace the ___s with the correct unless statement code so your program prints out "I'm writing Ruby programs!"

this is the error message

                      * (ruby):2: syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'

if false "I'm writing ruby programs!"
^


Replace this line with your code.


#2

can we see your code, please?


#3

this is what I typed:
hungry = false
if false "I'm writing ruby programs!"
print "I'm writing ruby programs!"
unless hungry
print "time to eat!"
end


Flanter
#4

you need to get rid of "I'm writing ruby programs!" on line two, tell me if this fixes anything


#5

did not fix it just said
(ruby):6: syntax error, unexpected $end, expecting keyword_end


#6

can I have the link to this exercise?


#7

#8

You have your syntax backwards, it needs to look like:

hungry = false

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

#9

thanks that worked!!!! :grinning:


#10

make sure that you look at the example and the information it gives you. Also, you needed to use puts instead of print.
glad you passed though


#11

Something to note:

if false

will always be false. Just because it IS false, does not mean it will be evaluated as true. It will always end up in the else pile.


#12

you're right, I thought that for some reason it said

if hungry == false

but if it's just if false, then it's evaluating false and not the variable.
edit: the below post clarifies that it's not evaluating false, but what it actually is doing.


#13

False cannot be evaluated. It is always false and the only way to make it true is to NOT it.

not false == true

This is how we get false to follow the true path.


#14

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