Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Week Two Collab</title>
- </head>
- <body>
- <div>
- <?php
- //Activity 1
- //pet name, age, owner, toy, and neutured or spayed
- //declaring variables
- $name1 = "Sally";
- $age1 = 9;
- $owner1 = "Greg";
- $fav_toy1 = "chewy bone";
- $NeuOrSprayed1 = "spayed";
- $name2 = "Max";
- $age2 = 5;
- $owner2 = "Lisa";
- $fav_toy2 = "cat nip";
- $NeuOrSprayed2 = "neutured";
- //output in structured sentence
- echo 'Pet Inforamtion: '.$name1 .' is '. $age1 . ' years old. '. ' Its owner is '.$owner1 . ', its favorite toy is '. $fav_toy1 .' and it is ' . $NeuOrSprayed1;
- echo '<br><br>Pet Inforamtion: '.$name2 .' is '. $age2 . ' years old. '. ' Its owner is '.$owner2 . ', its favorite toy is '. $fav_toy2 .' and it is ' . $NeuOrSprayed2;
- //declaring variable x and y to hold values 5 and 6
- //Declaring a variable in php
- $x = 5;
- $y = 6;
- $Sum = $x+ $y;
- echo '<br /><br />The sum is '.$Sum;
- $Difference = $y - $x;
- echo '<br /><br />The difference is '.$Difference;
- $Product = $x * $y;
- echo '<br /><br />The product is '.$Product;
- $Modulus = $y / $x;
- echo '<br /><br />The modulus is '.$Modulus;
- //incrementing a
- $a = 0;
- $a = ++$x;
- echo '<br /><br />The increment is '.$a;
- //decrementing b
- $b = 0;
- $b = --$y;
- echo '<br /><br />The decrement is '.$b;
- //when the code echo($num++) is executed, the number will stay at 4 because it's a post-increment meaning the program will return $num THEN increment $num by one
- //when the code echo(++$num) is executed, the number will increment by 1 because it's a pre-increment meaning the program will automatically add one to 4, the program will return a value of 5.
- //Activity 2
- /*
- using if-statements, test and display if the pet from activity 1 is:
- *7 yrs old
- *older than 7 and has an owner named ada
- *named terror or has slipper as favourite toy
- */
- if($age1 == 7){
- echo '<br /><br />'."Age is 7";
- } else {
- echo '<br /><br />'."No, Age is not 7";
- }
- if($age1 >= 7 && $owner1=="Ada"){
- echo '<br /><br />'."Age is older than 7 whose owner is Ada";
- } else {
- echo '<br /><br />'."No, Age is not older than 7 and its owner is not Ada";
- }
- if($name1 == "Terror" || $fav_toy1=="Slipper"){
- echo '<br /><br />'."Name is terror or favourite toy is slipper";
- } else {
- echo '<br /><br />'."Name is not terror nor favourite toy is slipper";
- }
- //using the if-else decision structure to display the day of the week based on the current character stored in day
- $day = 'U' ;//. 'M' . 'T' . 'W' . 'R' . 'F' . 'S';
- if($day == 'U') {
- echo '<br /><br />'."Sunday"; //I helped! ty!
- }
- if($day == 'M') {
- echo '<br /><br />'. "Monday";
- }
- if($day == 'T') {
- echo '<br /><br />'."Tuesday";
- }
- if($day == 'W') {
- echo '<br /><br />'."Wednesday";
- }
- if($day == 'R') {
- echo '<br /><br />'."Thursday";
- }
- if($day == 'F') {
- echo '<br /><br />'."Friday";
- }
- if($day == 'S') {
- echo '<br /><br />'."Saturday";
- }
- //using the ternary operator to assess if x is less than y.
- if($x < $y) {
- echo '<br /><br />'."X is smaller than y";
- } else {
- echo '<br /><br />'."X is not smaller than y";
- }
- if($x >= $y) {
- echo '<br /><br />'."X is greater than or equals to y";
- } else {
- echo '<br /><br />'."X is less than y";
- }
- //Activity 3
- //displaying odd numbers between 0 and 20 in descending order
- echo '<br><br>' . "Odd numbers between 0 and 20: ";
- for($i=20-1; $i>=0; $i=$i-2) {
- echo '<br><br>' . ($i . "<br>");
- }
- //displaying the 7-times table
- $count=0;
- $num=7;
- while ($count!=13){
- $multiple= $num * $count;
- echo '<br><br>' . $num. 'x'. $count.'='.($multiple . "<br>");
- $count = $count + 1;
- }
- //creating the associative array
- $course_ranking['Internet Tech'] = 7.5;
- $course_ranking['Info Proj. Management'] = 4;
- $course_ranking['Comp. Network, Arc & Protocol'] = 5;
- $course_ranking['Fundamentals of Research'] = 6;
- //displaying the array contents
- echo '<br><br>' . "Course Ranking for Internet Technology is " . $course_ranking['Internet Tech'];
- echo '<br><br>' . "Course Ranking for Information Project Management is " . $course_ranking['Info Proj. Management'];
- echo '<br><br>' . "Course Ranking for Computer Network Architecture & Protocol is " . $course_ranking['Comp. Network, Arc & Protocol'];
- echo '<br><br>' . "Course Ranking for Fundamentals of Research is " . $course_ranking['Fundamentals of Research'] . '<br>';
- //sorting the array
- $course_ranking = array('Internet Tech'=>7.5, 'Info Proj. Management'=>4, 'Comp. Network, Arc & Protocol'=>5, 'Fundamentals of Research'=>6);
- asort($course_ranking);
- foreach($course_ranking as $w => $w_value) {
- echo '<br><br>' . "Course=" . $w . ", Ranking=" . $w_value;
- echo "<br>";
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement