Bird
0
0

Which of the following is the correct syntax to check if the array arr includes the number 5?

easy📝 Syntax Q12 of 15
Ruby - Arrays
Which of the following is the correct syntax to check if the array arr includes the number 5?
Aarr.include(5)
Barr.includes?(5)
Carr.has?(5)
Darr.include?(5)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct method name and syntax

    The method to check presence is include? with a question mark at the end.
  2. Step 2: Verify method call on array

    It should be called as arr.include?(5), not include or includes?.
  3. Final Answer:

    arr.include?(5) -> Option D
  4. Quick Check:

    Correct method is include? with question mark [OK]
Quick Trick: Remember Ruby methods with ? end with a question mark [OK]
Common Mistakes:
  • Omitting the question mark in include?
  • Using incorrect method names like includes? or has?
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes