Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Practice Activity No.2- Strings and Variables (03.30.

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)

1. Use echo to print the string "Hello" concatenated to the string "World!"


2. We want to learn a little more about you, concatenate the given string “My name is “
with a string containing your name and a string containing a little information about you.
3. Create a variable and assign to it a string value. You can give the variable any valid
name you’d like and assign a string containing anything you want. End the statement
with a semicolon.
4. Declare a variable $biography and assign to it a string that starts with a new line
character and contains a sentence or two about you.
5. Create a variable $favorite_food and assign to it the string "\n", "pork", "chicken",
and "fish" concatenated together.

Practice Activity No.3- PHP Numbers (04.05.21)

Use echo to print the answer to the terminal. (15 points)


I’m trying to figure out how much money I should have. At the start of the day I had P104.
 I spent P5.25 on coffee
 A friend gave me P9 that he owed me.
 I went out for a meal. The bill was P25.50, but I also gave a 20% tip.
 Some friends and I found P20 on the ground and split it four ways.
I think that’s everything. Use a single chained operation to get your result!

Answer:
<? php
echo 104 - 5.25 + 9 - (25.50 + 25.50 * .2) + 20 / 4;

Practice No. 6- LOGICAL OPERATORS AND COMPOUND CONDITIONS

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!

Write a function, clapYourHands(). Your function should take in two boolean arguments.


The first represents happiness ($is_happy) and the second whether or not they “know it”
($know_it). If both are TRUE the function should return the string "CLAP!". Otherwise, it
should return the string ":(".

You should use the && operator to accomplish this task.


Checkpoint 2 Passed
Test your function! You should invoke your function at least twice—once with inputs that
return "CLAP!" and once with inputs that do NOT. Use echo so that the return value of
each function call is printed to the terminal.

You might also like