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

Objects in PHP Forum

View Course

432 points
563f564eb62548d5c9000854_286301216
Submitted by
Darkhorse2
about 2 years ago

8/10 - My code passed but doesn't appear in console - why?

Here's my script. I passed but console says - Parse error: syntax error, unexpected TSTRING, expecting TVARIABLE on line 13.
Why is this? If it's right why doesn't it read in console?
(line 13 is the public function construct name line).

<!DOCTYPE html>


Practice makes perfect!




<?php
class Dog {
public $numLegs = 4;
public $name;
public function__construct($name){
$this->name = $name;
}
public function bark(){
return "Woof!"
}

    public function greet(){
        return "My name is".$name.";  
    }
   $dog1 = new Dog("Barker");
   $dog2 = new Dog("Amigo");

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

   ?> 
  </p>
</body>

0 votes

permalink

in your greet function you have an extra quote marker. instead of:
return "My name is " .$name.";

it could be:
return "My name is $name";

or:

return "My name is " . $name;

additional note here. if you are using single quotes you will need to use the second option. reason: php with read variables within double quotes but not within single quotes.

426 points
9a74e1277d8e32358137a88e715f067c?s=140&d=retro
Submitted by
Bret Wagner
about 2 years ago