Control Flow Quiz


What is the value of the variable color?

calculation = 45 - 8 / 2

if calculation % 2 == 0
    color = "turquoise"
else
    color = "magenta"
end

Show Answer

What is the output of the following?

if 66 > 8
    puts("sixty six is greater than eight")
end

character = "k"

if "t" < character
    puts("character is greater than 't'")
elsif "g" < character
    puts("character is greater than 'g'")
else
    puts("huh?")
end

Show Answer

What is the value of my_variable in the following?

my_variable = 6
your_variable = 19

if my_variable % 3 == 0
    her_variable = your_variable + my_variable

    if her_variable > 30
        my_variable = 0
    elsif her_variable > 20
        my_variable = her_variable + my_variable
    elsif her_variable > 10
        my_variable = her_variable - your_variable
    else
        my_variable = her_variable
    end
else
    my_variable = my_variable + 1
end

Show Answer