FAQ: Object-Oriented Programming I - When Good isn't Good Enough

This community-built FAQ covers the “When Good isn’t Good Enough” exercise from the lesson “Object-Oriented Programming I”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise When Good isn’t Good Enough

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

In this exercise, why was “Punch to the chops!” printed to the console when only “Instead of breathing fire…” was part of the puts statement?

1 Like

do you know what super is? It calls the parent method, which is why punch the chops is also printed

This exercise printed out:

Instead of breathing fire…
Punch to the chops!

I don’t understand why this happened. We have not created any Dragons, so we have not called the Dragon fight method with any Dragon instance.

Maybe the exercise validation calls the methods, resulting in output being shown. You could attempt to run the code on repl.it, see what output you get.

He means, why did the method called by “super” was printed when it had no “puts” or “print” there. Why did that “return” method print something to the screen?

i don’t get any output to screen. Please include your code when asking a question, to better help me understand the issue

It doesn’t have any output if you run it as is without doing the exercise. If you do what the exercise says it has you add a puts and a return. What seems to be happening is whatever validation logic there is is also doing puts Dragon.new("some name").fight in the background. This results in the fight method being called outside what users here can see. Not good for first time learners since they can be confused by the unexpected output as can be seen from the already existing comments.

Here is what the code looks like if you do the exercise:

class Creature
def initialize(name)
@name = name
end

def fight
return “Punch to the chops!”
end
end

class Dragon < Creature
def fight
puts “Instead of breathing fire…”
super
end
end

2 Likes

Out of curiosity, I switched the puts statement (“Instead of breathing fire”) and super.
This resulted in the output:
Instead of breathing fire
37

Why has “37” appeared in the output?
I’ve copied my code below

class Creature
  def initialize(name)
    @name = name
  end
  
  def fight
    return "Punch to the chops!"
  end
end

# Add your code below!
class Dragon < Creature
  def fight
    super
    puts "Instead of breathing fire..."
  end
end

thing_one = Creature.new("Bill")
thing_two = Dragon.new("Tommy")

puts thing_one.fight
puts "=== end of thing one ==="
puts thing_two.fight```

I have the same thing where it has printed out statements and I have no idea why.

class Creature
  def initialize(name)
    @name = name
  end
  
  def fight
    return "Punch to the chops!"
  end
end

# Add your code below!

class Dragon < Creature
def fight
puts "Instead of breathing fire..."
super
end
end

The full code is here and it shows it passes to the next lesson

The exercise very like does validation by calling the methods, which then shows in the output window

1 Like

I don’t quite understand what you mean.
Is it something built into the exercise by Codecademy which we don’t see and they executed it?
if that’s the case, the end result made it very confusing for a beginner like me

1 Like

the exercise/your code needs to be validated. So yes, there is certainly happening stuff in the background.

creating a class instance and trying to call the different methods is a very idea to improve your understanding :slight_smile:

1 Like

In the example, the call to super is followed by end. However, when I put an end statement on my super call, I got a syntax error. I get the same error even when I add a comment line indented below the super. Removing the end sorted it, but this is confusing. I don’t know if Ruby requires an end after super or not because so far I have been given conflicting information, and as other users point out, the interpreter is adding unseen code in order to mark the exercise.

1 Like