This forum is now read-only. Please use our new forums! Go to forums
Hey, did you forget add my name as a property to the object? :-P
I am getting the same error message back also. I have my greet() function and function __construct() in side of my class Person. My preview window seems to be displaying the correct info. I need help as well, can anyone lend a hand?
Here is my current code:
<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname, $lastname, $age){
$this -> firstname = $firstname;
$this -> lastname = $lastname;
$this -> age = $age;
}
public function greet() {
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
}
public function tellage() {
return $this->firstname . " is " . $this->age . " years old.";
}
}
$teacher = new Person("Boring", "Adult", 55);
$student = new Person("First", "Last", 24);
echo $teacher->greet() . "<br />";
echo $student->greet() . "<br />";
echo $teacher -> tellage() . "<br />";
echo $student -> tellage() . "<br />";
?>
Thank you for your time and consideration.
Answer 543c3ec49c4e9d62e9000593
I figured the issue. You have to type “boring” exactly like that, not “BORING, Boring, or any other combination. This lesson is looking for that information to be exact or else it says it is incorrect.
Below is a snippet of that line:
$teacher = new Person(“boring”, “12345”, 12345);
And here is my now working code: (NOTICE: I have added a bit that tells the age also just for practice, this can be included and still get a correct answer but is not necessary.)
<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname, $lastname, $age){
$this -> firstname = $firstname;
$this -> lastname = $lastname;
$this -> age = $age;
}
public function greet() {
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
}
public function tellage() {
return $this->firstname . " is " . $this->age . " years old.";
}
}
$teacher = new Person("boring", "12345", 12345);
$student = new Person("Jeremy", "Polen", 24);
echo $teacher->greet() . "<br />";
echo $student->greet() . "<br />";
echo $teacher -> tellage() . "<br />";
echo $student -> tellage() . "<br />";
?>
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency