Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Hashes
Identify the error in this Ruby code:
arr = [1, 2, 3]
arr(1) = 10
puts arr.inspect
AUsing parentheses instead of brackets for array access
BAssigning value to array element is not allowed
CMissing quotes around number 10
DArray cannot be printed with puts
Step-by-Step Solution
Solution:
  1. Step 1: Check array element assignment syntax

    Ruby arrays use square brackets for indexing, not parentheses.
  2. Step 2: Identify the syntax error

    Using arr(1) = 10 causes a syntax error; correct is arr[1] = 10.
  3. Final Answer:

    Using parentheses instead of brackets for array access -> Option A
  4. Quick Check:

    Array indexing uses brackets, not parentheses [OK]
Quick Trick: Use brackets [] for array indexing, not parentheses () [OK]
Common Mistakes:
MISTAKES
  • Using parentheses for array indexing
  • Thinking assignment is disallowed
  • Confusing printing methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes