Skip to Content
Learn
Control Flow in Ruby
Equal or Not?

In Ruby, we assign values to variables using =, the assignment operator. But if we’ve already used = for assignment, how do we check to see if two things are equal? Well, we use ==, which is a comparator (also called a relational operator). == means “is equal to.” When you type

x = 2 y = 2 if x == y print "x and y are equal!" end

you’re saying: “if x equals y, print ‘x and y are equal!’” You can also check to see if two values are not equal using the != comparator.

Instructions

1.

We’ve got two variables in the editor: is_true and is_false. Replace the __ with == or != to make is_true evaluate to true and is_false evaluate to false.

Folder Icon

Take this course for free

Already have an account?