Skip to content

Commit 773a365

Browse files
author
dima_los
committed
Added Tutorial 7 code and made some fixes to practice assignments && solutions
1 parent 1290586 commit 773a365

9 files changed

+72
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$myCoins = 55;
4+
$shieldPrice = 50;
5+
$isShieldAvailable = false;
6+
7+
if (($myCoins > $shieldPrice || $myCoins === $shieldPrice) && $isShieldAvailable) {
8+
echo 'You have enough coins to buy the shield!';
9+
} else {
10+
echo 'You cannot buy the shield.';
11+
}

tutorial-007-operators/identical.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$key = 'Obsidian';
4+
$entranceLock = 'Arcane';
5+
6+
if ($key !== $entranceLock) {
7+
echo 'You may enter the dungeon';
8+
} else {
9+
echo 'You have the wrong key';
10+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$hasSword = true;
4+
$hasShield = false;
5+
6+
if ($hasSword && $hasShield) {
7+
echo 'You have defeated the dragon!';
8+
} else {
9+
echo 'Game over!';
10+
}
11+
12+
// 1) pass 1,2,3 as an input to an operator
13+
// 2) the operator does some work
14+
// 3) then it returns a result
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$isHealingPotionExpired = true;
4+
5+
if (!$isHealingPotionExpired) {
6+
echo 'You have restored 7 hit points.';
7+
} else {
8+
echo 'You health is low!';
9+
}

tutorial-007-operators/logical-or.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$stoneBridgeSafe = false;
4+
$woodenBridgeSafe = false;
5+
6+
if ($stoneBridgeSafe || $woodenBridgeSafe) {
7+
echo 'You can cross the river!';
8+
} else {
9+
echo 'You need to find another path!';
10+
}

tutorial-007-operators/practice-assignments/1-potion-brewer.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22
/**
3-
**Description:**
3+
**Potion Brewer: Mixing Ingredients**
44
5-
You are an alchemist in a fantasy world. You have four variables: $herb, $flower, $mushroom, and $crystal, each of which can be true (available) or false (not available).
5+
You are an alchemist in a fantasy world.
6+
7+
You have four variables: $herb, $flower, $mushroom, and $crystal,
8+
each of which can be true (available) or false (not available).
69
710
- You need both $herb and $flower to brew a healing potion.
811
- You need either $mushroom or $crystal to brew a mana potion.
@@ -20,7 +23,7 @@
2023
$crystal = true;
2124

2225
if ($herb && $flower) {
23-
echo 'Healing potion brewed!';
26+
echo 'Healing potion brewed!🍔';
2427
} elseif ($mushroom || $crystal) {
2528
echo 'Mana potion brewed!';
2629
} else {

tutorial-007-operators/practice-assignments/2-castle-gatekeeper.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<?php
22
/**
3-
**Description:**
3+
**Castle Gatekeeper: Granting Entry**
44
55
You are the guardian of a magical castle.
6+
67
There are three variables: $password, $royalSeal, and $nightTime.
78
The $password can be a string, while $royalSeal and $nightTime are booleans.
89
9-
- Anyone with the correct $password ("OpenSesame") can enter during the day.
10+
- Anyone with the correct $password ("Castle Lord") can enter during the day.
1011
- If it's $nightTime, even with the correct password, they need to have the $royalSeal as well.
1112
1213
**What to Do:**
1314
- If it's daytime and the password is correct, echo 'Welcome to the castle!'
1415
- If it's nighttime, they have the password and the royal seal, echo 'Welcome, noble guest!'
1516
- Otherwise, echo 'Entry denied!'
1617
*/
17-
$password = 'OpenSesame';
18+
$password = 'Castle Lord';
1819
$royalSeal = true;
1920
$nightTime = true;
2021

21-
if ($password === 'OpenSesame' && !$nightTime) {
22+
if ($password === 'Castle Lord' && !$nightTime) {
2223
echo 'Welcome to the castle!';
23-
} elseif ($nightTime && $password === 'OpenSesame' && $royalSeal) {
24+
} elseif ($nightTime && $password === 'Castle Lord' && $royalSeal) {
2425
echo 'Welcome, noble guest!';
2526
} else {
2627
echo 'Entry denied!';

tutorial-007-operators/practice-assignments/3-wizards-challenge.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/**
33
**Wizard's Challenge: Spell Casting**
44
5-
**Description:** You are a wizard apprentice.
5+
You are a wizard apprentice.
6+
67
You have a variable $mana (a number) and two booleans, $hasSpellbook and $fullMoon.
78
- You need at least 50 $mana and the $hasSpellbook to cast a basic spell.
89
- If it's a $fullMoon, even with lower mana (let's say 30), you can still cast the basic spell with the spellbook.

tutorial-007-operators/practice-assignments/4-treasure-hunter.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
/**
3-
**Description:** You are on a quest for treasure.
3+
**Treasure Hunter: Finding Loot**
4+
5+
You are on a quest for treasure.
6+
47
You have three booleans: $hasMap, $hasCompass, and $foundXMark.
58
69
- If you have both $hasMap and $foundXMark, you can locate the buried treasure.

0 commit comments

Comments
 (0)