This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

471 points
Dac0d9ddade5a3d470a2b7d590d34b50?s=140&d=retro
Submitted by
ninaruth
about 3 years ago

Oops, try again. I can't see your dogs. Are they stored in the correct variables?

So my code appears to be correct in that it's printing what it's supposed to print, but it won't pass and tells me "Oops, try again. I can't see your dogs. Are they stored in the correct variables?" Is something actually off in my code or is this just a bug with the site? I've tried refreshing many times as well as adding and removing semicolons which sometimes seems to help for some reason. Here is my code:

<?php
    class Dog {
        public $numLegs = 4;
        public $name;
        public function __construct($name) {
            $this->name = $name;
        }
        public function bark() {
           return "Woof!"; 
        }
        public function greet() {
           return "Hello, my name is " . $this->name . "!"; 
        }
    }
    $dog1 = new Dog("Barker");
    $dog2 = new Dog("Amigo");

    echo $dog1->bark();
    echo $dog2->greet();
    ?>

2 votes

permalink

I can't see anything wrong with your code, in fact I've copied and pasted it into the same section and it passed for me. I'd suggest cutting and pasting what you have back in, see if that works. Maybe cut one line of code out, paste it back in. Refresh a time or two after doing one of those. Your code is fine so it might just be a matter of it not recognizing it for some reason.

919 points
59f47a0e854be943b60002ef_696126019
Submitted by
Travis Wisecup
about 3 years ago


0 votes

permalink

Thanks. I thought it was right, I just wanted to be sure.

471 points
Dac0d9ddade5a3d470a2b7d590d34b50?s=140&d=retro
Submitted by
ninaruth
about 3 years ago