Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class named Car.
Ruby
class [1] end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for classes.
Using names that do not start with a capital letter.
✗ Incorrect
The class name must start with a capital letter. Car is the correct class name.
2fill in blank
mediumComplete the code to define a method named start inside the class.
Ruby
class Car def [1] puts 'Car started' end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than requested.
Capitalizing method names (they should be lowercase).
✗ Incorrect
The method name should be start as requested.
3fill in blank
hardFix the error in the class declaration by completing the blank.
Ruby
class [1] def initialize @speed = 0 end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class names.
Using variable names instead of class names.
✗ Incorrect
Class names must start with a capital letter. Car is correct.
4fill in blank
hardFill both blanks to create a class Bike with a method ride that prints 'Riding'.
Ruby
class [1] def [2] puts 'Riding' end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up class and method names.
Using incorrect capitalization.
✗ Incorrect
The class name is Bike and the method name is ride as requested.
5fill in blank
hardFill all three blanks to create a class Plane with a method fly that prints the speed stored in @speed.
Ruby
class [1] def [2] puts "Flying at #{ [3] } km/h" end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the @ in instance variable.
Using wrong method or class names.
✗ Incorrect
The class is Plane, method is fly, and the instance variable is @speed.