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!
I’m having the same issue, and this isn’t actually helping me.
In a ternary operator, the expressions on either side of the : are returned - at least, that’s what the course says:
`* The first operand is a condition to check. This is followed by a question mark `?` .
* The second operand is an expression to `return` if the condition is `TRUE` . This is followed by a colon ( `:` ).
* The third operand is an expression to `return` if the condition is `FALSE` .`
And in fact, the hint for the exercise says that this is what the code should look like:
$items <= 12 ? "express lane" : "regular lane";
This is what I’ve written, but I still get the same error
While I understand where this might have been confusing, we ought to keep something in mind.
It’s essential to understand that it is in fact the function itself that has to return a value.
Whether we’re dealing with a ternary operator or not, the function has to return something.
function chooseCheckoutLane($items){
if ($items <= 12){
return "express lane";
} else {
return "regular lane";
}
}
Here it clearly states that you’ll either return express lane, or regular lane. Leave return out and it simply won’t return anything. The hint doesn’t give you an outright answer, and is actually focused on the ternary itself, not the return part. Return was likely covered in Introduction to Functions in PHP.
I am confused by below explanation can some please help me to understand?
by default the variable is ‘FALSE’ but in the explanation it says if its true we assign purple color but purple color is in the FALSE statement.
Explanation: In the code above, our condition checks the value of the $isClicked variable. If it’s TRUE we assign $link_color to "purple" , otherwise we assign it the value "blue" . Our code is somewhat repetitive—the code in each code block is only slightly different.