0
0
Rubyprogramming~10 mins

Comments and documentation in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a single-line comment in Ruby.

Ruby
[1] This is a comment
Drag options to blanks, or click blank then click option'
A#
B!
C//
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using // or -- which are comment symbols in other languages.
Forgetting to add any symbol before the comment text.
2fill in blank
medium

Complete the code to add a multi-line comment using =begin and =end in Ruby.

Ruby
=begin
[1]
This is a multi-line comment.
=end
Drag options to blanks, or click blank then click option'
AIgnore this text
BThis is not a comment
CCode goes here
DThis is a comment
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the text empty between =begin and =end.
Using code instead of comment text inside the block.
3fill in blank
hard

Fix the error in the comment syntax below.

Ruby
[1]
Drag options to blanks, or click blank then click option'
A# This is a comment in Ruby
B-- This is a comment in Ruby
C/* This is a comment in Ruby */
D=begin This is a comment =end
Attempts:
3 left
💡 Hint
Common Mistakes
Using comment symbols from other languages like // or /* */.
Trying to use multi-line comment syntax for a single line.
4fill in blank
hard

Fill both blanks to create a method with a comment describing its purpose.

Ruby
# [1]
def greet(name)
  puts "Hello, #{name}!"
end
Drag options to blanks, or click blank then click option'
AThis method prints a message
BThis method greets a person
CThis method calculates sum
DThis method sorts a list
Attempts:
3 left
💡 Hint
Common Mistakes
Writing comments unrelated to the method's purpose.
Leaving the comment blank.
5fill in blank
hard

Fill all three blanks to add a multi-line comment explaining the code.

Ruby
=begin
[1]
[2]
[3]
=end
def add(a, b)
  a + b
end
Drag options to blanks, or click blank then click option'
AThis method adds two numbers
BIt takes two inputs
Cand returns their sum
DThis method multiplies two numbers
Attempts:
3 left
💡 Hint
Common Mistakes
Writing incorrect descriptions about the method.
Using single-line comment syntax inside multi-line comment block.