Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Operators and Expressions
Identify the error in this Ruby code:
num1 = 5
num2 = 2
result = num1 // num2
puts result
AMissing multiplication operator
BNo error, code is correct
CUsing % instead of /
DUsing // instead of / for division
Step-by-Step Solution
Solution:
  1. Step 1: Check division operator syntax in Ruby

    Ruby uses / for division, not //.
  2. Step 2: Identify invalid operator usage

    // is not a valid operator in Ruby and causes syntax error.
  3. Final Answer:

    Using // instead of / for division -> Option D
  4. Quick Check:

    Division uses /, not // [OK]
Quick Trick: Use single / for division in Ruby [OK]
Common Mistakes:
MISTAKES
  • Using // like in other languages
  • Confusing % with division
  • Missing operator between variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes