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 #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
Hi there,
As a beginner and following this course it took me a long time to figure out why in this exercise a switch wouldn’t work the same as an if/else statement. Apparently a switch does loose comparisons with “==” and gets different results than “===”, especially in this exercise. Maybe good to mention that in the part about switch statements. Now in the course it is introduced as if switch is a good substitute for “===” if/else statements.
They do mention the difference between them in the Identical and Not Identical Operators:
When looking through PHP code, you may encounter another operator—the equal operator (==). Like the identical operator, the equal operator will return TRUE if the left operand is the same as the right operand and FALSE if it’s not. But the equal operator is less strict than the identical operator and can have some hard to predict results, so we prefer to only use the identical operator.
If you use the equal operator, then some things might be interpreted by the computer differently to what you actually want.
For example, 5 == "5" can come up as TRUE, where 5 === "5" will come up as false.
Yes, thanks. But I meant specifically what type of comparison a switch statement does (==), that was not mentioned. For this exercise it makes all the difference.
Ah, okay, I see what you mean. Yea, a switch statement only does a loose comparison, which means it uses ==. If you want to use a strict comparison, then its better to use an if / elseif statement.
So for this exercise, an if / elseif would have been better.
I agree that they should mention this in that part of the lesson.
Ok, I know, I thought they want us too practice what we learned. Still my solution also should be working, but the error says, that its giving the wrong return value. Any clue why?
In Truthy and Falsy, i tried to use an undefined variable and it won’t accept my answer and it gives me this message instead:
PHP Notice: Undefined variable: test in /home/ccuser/workspace/php-truthy-falsy/src/index.php on line 17
note that it does print False in the console before giving me this message. I just wonder why it won’t count as a good answer for me to complete the task.
I understand that this message is important to let me know there is something wrong with the code and i understand why it gives me the message, my question is why codecademy doesnt accept my code when this is what they ask?
quote: Test your function! Invoke your function at least once with a truthy value and at least once with a falsy value. Be sure to use echo to print the results to the terminal.
it IS a falsy value since it is part of the list they gave my in the previous paragraph:
quote:
Empty strings
null
an undefined or undeclared variable
an empty array
the number 0
the string "0"
They could have just give me the message, but accept my answer as it is what they are looking for (i tried all the falsy values to find out this one wasn’t accepted).