Jump to content

Learning PHP with CodeAcademy


Kasha

Recommended Posts

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:

  1. Create a class called Cat.
  2. Add two public properties to this class: $isAlive ought to store the value true and $numLegsshould contain the value 4.
  3. Add a public $name property, which gets its value via the__construct()or.
  4. Add a public method calledmeow(), which returns "Meow meow".
  5. Create an instance of the Catclass, which has the $name "CodeCat".
  6. 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'!
Link to comment
https://forums.phpfreaks.com/topic/293774-learning-php-with-codeacademy/
Share on other sites

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();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.