There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Why don’t these run the same? The first is my answer to the exercise, the second is the official solution. I don’t see any reason why they wouldn’t work the same way. Can anybody help?
echo “Hello, there. What’s your first name?\n”;
$first_name = readline(">> “);
if (strlen(first_name) > 8) {
echo "Hi, {first_name}. That’s a long name.”;
} elseif (strlen(first_name) > 3) {
echo "Hi, {first_name}.";
} else {
“Hi, ${first_name}. That’s a short name.”;
}
__________ Official Solution __________________
echo “Hello, there. What’s your first name?\n”;
$name = readline(">> ");
$name_length = strlen($name);
if (name_length > 8) {
echo "Hi, {name}. That’s a long name.";
} elseif (name_length > 3) {
echo "Hi, {name}.";
} else {
echo “Hi, ${name}. That’s a short name.”;
}
<?php
namespace Codecademy;
echo "Hello, there. What's your first name?\n";
$first_name = readline(">>");
$name_length = strlen($first_name);
if ($name_length > 8) {
echo "Hi, ${first_name}. That's a long name.";
}elseif ($name_length > 3) {
echo "Hi, ${first_name}.";
} else {
"Hi, ${first_name}. That's a short name.";
}
I get an error saying " If their name is between 4 and 8 characters (inclusive), your program should print: Hi, [NAME]. For example, if the user input was Alexis your program should print: Hi Alexis."
I have no idea why I am getting this.
This is the official solution:
<?php
namespace Codecademy;
echo "Hello, there. What's your first name?\n";
$name = readline(">> ");
$name_length = strlen($name);
if ($name_length > 8) {
echo "Hi, ${name}. That's a long name.";
} elseif ($name_length > 3) {
echo "Hi, ${name}.";
} else {
echo "Hi, ${name}. That's a short name.";
}
Little bit confused, I can’t get this to pass and the reason I am being given isn’t true. It says, entering ‘Alexis’ should return a response of ‘Hi Alexis’. The thing is it does that.
Hi, why are we using {} to call the variable? I don’t remember this being explained before, and is not even used on the description example. Some information is missing here.
Same problem I’m experiencing. Frustrating!
I did learn about this string interpolation form: ${var} (complex syntax)
This was deprecated at some point, but I didn’t verify which release.
I’m moving on as well - hope I don’t keep encountering this kind of problem where my code runs, but the lesson module is broken.