Professional Documents
Culture Documents
Practice Activities
Practice Activities
21)
Write your code using your Zira editor/ Sublime Text or Visual Studio Code editor. Screenshot
your output and comment it here. (5 points each)
Answer:
<? php
echo 104 - 5.25 + 9 - (25.50 + 25.50 * .2) + 20 / 4;
1. We have a special quirk: we’ll eat only when we’re hungry or if it’s dessert. Let’s use the
logical || operator to represent this situation with code.
Write a function willWeEat(). Your function should take as its first argument a string
representing a meal type ($meal_type), and as its second argument a boolean of
whether or not we’re hungry ($is_hungry).
If either the meal is "dessert" or it’s TRUE that we’re hungry, the function
should return "Yum. Thanks!". Otherwise, it should return "No thanks. We're not
hungry."
Invoke your function at least twice—once with inputs that return "Yummy! Thanks!"and
once with inputs that return "No thanks. We're not hungry.". Be sure to use echo to print
the return values to the terminal.
2. There’s a children’s song we always get stuck in our head: If You’re Happy and You
Know It. Let’s honor it by translating it into code!