This forum is now read-only. Please use our new forums! Go to forums
8/10 and 9/10 <p></p> don't contain anything
I am getting an error message saying that my
tags are empty even though the result pane is showing the proper echo. I have tried resetting the code and refreshing my browser page and I still get the same error message. Here is my code in case I am doing something wrong.<?php
// Your code here
class Cat {
public $isAlive = true;
public $numLegs = 4;
public $name;
public function __construct($name){
$this->name = $name;
}
public function meow() {
return "<p>Meow meow</p>";
}
}
$cat1 = new Cat("CodeCat");
echo $cat1->meow();
?>
Answer 5378624f9c4e9de9f20035af
When the PHP code is like this:
<p>
<?php
echo "Personal Homepage: Hypertext Processor";
?>
</p>
Whatever is echo
ed comes directly inside of the <p>
tags. So, the above code would, on executing, produce:
<p>Personal Homepage: Hypertext Processor</p>
To test, apply a CSS rule, say color:blue;
on p
element, and notice the text that PHP echo
ed is blue
!
Now, note that the <?php ?>
tags for this exercise are already inside of p
tags. So, whatever you echo
, say "Meow meow!"
, would come directly inside of the p
tag, and the exercise would pass you.
But by adding an extra <p>
, and outputting like echo "<p>Meow meow</p>"
, it would confuse the code checker and it would throw an error.
Thus, simply, don’t use the <p>
tags in output strings.
Hope that clarifies your doubt!
Answer 53be98198c1ccc7e64001c01
4 comments
you have the exact same code I had and for some reason yours works and mine didn’t. what the actual fu. how very frustrating
same code as me :D
i copy my code then refresh the page and paste it back it work :)
That’s what I do too, half the time. It’s ridiculous.
Answer 549691109113cbecc9004ac6
Answer 551719e351b8874f69002075
Answer 53980d538c1ccc7bc9001340
just remove the
and
in your return meow meowpublic function meow() {
return "Meow meow";
}
reason is your already in
tagAnswer 5423405152f863b989000337
I would like to know why this is not working? i pass the question but i get this error: Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION on line 24 class Dog{ public $numLegs = 4; public $name;
public function __construct($name){
$this->name = $name;
}
public function bark(){
return "Woof!";
}
public function greet(){
return "Hi my name is " . $this->name . " i am awesome.";
}
$dog1 = new Dog("Barker");
$dog2 = new Dog("Amigo");
echo $dog1->bark();
echo "<br />";
echo $dog2->greet();
2 comments
Your class curly bracket class Dog {
is not closed.
thx (:
Answer 537774d552f863b48e00152d
Not really adding an answer to my own question, but rather adding more of my confusion. I removed the
tags from the meow() method and now the code passes. I thought that the tags were supposed to be there. Other lessons worked with the tags in. Don’t these tags allow multiple echos to display on separate lines rather than in a row on the same line?Answer 53777637631fe9ef9d001715
Got the same error on 10/10 with this code:
<?php /*Your code here */
echo "<p>Now I know the basics of OOP!</p>";
?>
Again, removed the tags and it passed. I guess I am just too over zealous with the paragraph tags. So… my question now is “When should
tags be used in a function’s return and when should they not be used?”1 comments
the issue isn’t your tags. The issue is that the confirmation tests are VERY specific. If your final HTML doesn’t look the way it expects you will fail.
Answer 53dcda019c4e9dd38b001a23
2 comments
you need to change the call to the method: echo $cat1 -> cat(); to echo $cat1 -> meow();
Correct syntax is : $cat1 = new Cat(“CodeCat”);
echo $cat1->meow();
Answer 556820d19113cb960b0003fe
class cat{ public $alive=true; public $numlegs=4; public $name; public function __construct($name){ $this->name=$name; } public function meow(){ return “meow meow”; } }
$name =new cat("codecat");
echo $name->meow();
``but it say did u create a cat class ??? what to do
Answer 55ab35ae76b8fed6bc0002fa
Answer 55d227609113cb4b150002d5
Answer 5615466ee39efe7768000230
Thanks for your help guys!
Answer 55e49f1cd3292fea8c00062d
Answer 53bdbda180ff3300ae0009ab
<?php
class Cat{
public $isAlive = true;
public $numLegs = 4;
public $name;
public function __construct($name){
$this->name = $name;
}
public function meow(){
return "Meow meow";
}
}
$cat1 = new Cat("CodeCat");
echo $cat1->meow();
?>
Answer 5395e64f80ff332d45000540
I think your code at this level:
$cat1 = new Cat("CodeCat");
Is wrong. The $cat1 is not defined to which property it belongs in the Cat class. It should look like this:
$cat1 = new Cat($name = "CodeCat");
This sends the new “CodeCat” to the name property.
2 comments
Wouldn’t your constructor direct it to the proper property?
@mikedegrande its good you try my suggestion, if it works learn from what I said, if not please post error in your reply. And NO. Computers do not “Think” they do as they are told and in this case you have not explained what it should do properly. So the computer is a bit confused.
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
2 comments
This is crazy my code was Perfect but not working I have copy pasted the same code from here it is working. I have learnt nothing, I don’t know where was the mistake
same