Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - File IO
Identify the error in this Ruby code snippet:
File.write("notes.txt") "Remember this"
AFile.write requires a block for writing
BMissing second argument for content to write
CFilename must be a symbol, not string
DFile.write cannot write strings
Step-by-Step Solution
Solution:
  1. Step 1: Check File.write parameters

    File.write requires filename and content as arguments.
  2. Step 2: Identify missing content argument

    The code only passes filename, missing the string to write.
  3. Final Answer:

    Missing second argument for content to write -> Option B
  4. Quick Check:

    File.write needs filename and content [OK]
Quick Trick: File.write needs filename and content arguments [OK]
Common Mistakes:
  • Omitting content argument
  • Using symbol instead of string for filename
  • Thinking block is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes