Jump to content

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'!
Edited by Kasha
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();
Edited by Strider64
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.