Logic Quiz

What does "cat" >= "dog" return?

It causes an error. "cat" true false "cat" is alphabetically less than (prior to)"dog"; therefore, the operation returns false. Both operands are strings, so the comparison is valid.

What does "cat" != [] return?

It causes an error. "cat" true false "cat" does not equal an empty array; therefore, the operation returns true. One can check for equality across data types, so the comparison is valid.

What does [] < [true] return?

It causes an error. "cat" true false Arrays can only be compared for equality; therefore, the operation causes the Ruby interpreter to throw an error.

What does 2 < 3 && 2.even? return?

It causes an error. true false Because both 2 < 3 and 2.even? are true (both expressions evaluate to true), the statement returns true.

What does 2.odd? && 2 < 3 return?

It causes an error. true false Because 2.odd? evaluates to false, and the operator is &&, the statement short-circuits and returns false regardless of the second operand.

What does 2.odd? || 2 < 3 return?

It causes an error. true false Because 2.odd? evaluates to false, and the operator is ||, the Ruby interpreter does not short-circuit and evaluates the second operand. Because 2 < 3 evaluates to true, the statement returns true.

results matching ""

    No results matching ""