Kasha Posted January 9, 2015 Share Posted January 9, 2015 (edited) Hey people! I'm new here and I desperately need your help! I have my PHP exam on monday so I'm practicing with codeacademy. I know it's easy stuff for you, but don't judge and help a girl out please! These are the instructions: Create a class called Cat. Add two public properties to this class: $isAlive ought to store the value true and $numLegsshould contain the value 4. Add a public $name property, which gets its value via the__construct()or. Add a public method calledmeow(), which returns "Meow meow". Create an instance of the Catclass, which has the $name "CodeCat". Call the meow() method on thisCat and echo the result. This is my code: <?php class Cat { public $isAlive = true ; public $numLegs = 4 ; public function __construct ($name) { $this -> name = $name ; } public function meow () { return "Meow meow" ; } } $cat1 = new Cat ("Codecat", "Codecat" , "Codecat") ; echo $cat1->meow (); ?> This is the error: Oops, try again. Hey, your 'new' cat ought to be called 'CodeCat'! Edited January 9, 2015 by Kasha Quote Link to comment https://forums.phpfreaks.com/topic/293774-learning-php-with-codeacademy/ Share on other sites More sharing options...
Strider64 Posted January 9, 2015 Share Posted January 9, 2015 (edited) Close -> <?php class Cat { public $isAlive = true; public $numLegs = 4; public function __construct($name) { $this->name = $name; } public function meow() { return "Meow meow"; } } $cat1 = new Cat('CodeCat'); echo $cat1->meow(); Edited January 9, 2015 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/293774-learning-php-with-codeacademy/#findComment-1502271 Share on other sites More sharing options...
Kasha Posted January 9, 2015 Author Share Posted January 9, 2015 Yaaaay it works!! Thaaanks....I found the problem...I wrote "Codecat" instead of "CodeCat" Problem solved. Quote Link to comment https://forums.phpfreaks.com/topic/293774-learning-php-with-codeacademy/#findComment-1502273 Share on other sites More sharing options...
Barand Posted January 9, 2015 Share Posted January 9, 2015 If you think that was the problem then you have many more problems when it comes to coding. Quote Link to comment https://forums.phpfreaks.com/topic/293774-learning-php-with-codeacademy/#findComment-1502275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.