-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.php
More file actions
247 lines (222 loc) · 8.13 KB
/
Copy pathindex.php
File metadata and controls
247 lines (222 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
$title = "Exo 1";
require 'header.php';
?>
<!-- QUESTION 1 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 1</h2>
<p class="exercice-txt">Evrivez la phrase suivante dans une balise HTML P en utilisant les 2 variables ci-dessous :</p>
<p class="exercice-txt">"<i>Firstname</i> a obtenu <i>score</i> points à cette partie."</p>
<div class="exercice-sandbox">
<?php
$firstname = "Michel";
$score = 327;
echo "<p> $firstname a obtenu $score points à cette partie </p>"
?>
</div>
</section>
<!-- QUESTION 2 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 2</h2>
<p class="exercice-txt">Afficher dans une liste HTML le nom des produits suivants et leurs prix.</p>
<div class="exercice-sandbox">
<?php
$nameProduct1 = "arc";
$priceProduct1 = 10.30;
$nameProduct2 = "flèche";
$priceProduct2 = 2.90;
$nameProduct3 = "potion";
$priceProduct3 = 5.20;
echo "<ul>
<li>$nameProduct1 : $priceProduct1</li>
<li>$nameProduct2 : $priceProduct2</li>
<li>$nameProduct3 : $priceProduct3</li>
</ul>"
?>
</div>
</section>
<!-- QUESTION 3 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 3</h2>
<p class="exercice-txt">Calculer le montant total de la commande des produits ci-dessus avec les quantités ci-dessous et appliquez lui une remise de 10%.</p>
<div class="exercice-sandbox">
<?php
$quantityProduct1 = 1;
$quantityProduct2 = 10;
$quantityProduct3 = 4;
$total = (($priceProduct1 * $quantityProduct1) + ($priceProduct2 * $quantityProduct2) + ($priceProduct3 * $quantityProduct3)) * 0.9;
echo "$total"
?>
</div>
</section>
<!-- QUESTION 4 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 4</h2>
<p class="exercice-txt">Affichez le prix le plus élevé des 3 produits ci-dessus.</p>
<div class="exercice-sandbox">
<?php echo max($priceProduct1, $priceProduct2, $priceProduct3) ?>
</div>
</section>
<!-- QUESTION 5 -->
<?php
$text1 = "Le marchand m'a vendu un arc et des flèches.";
?>
<section class="exercice">
<h2 class="exercice-ttl">Question 5</h2>
<p class="exercice-txt">Affichez dans une liste HTML le nom des produits de la question 2 qui sont présents dans la phrase : "<?= $text1 ?>"</p>
<div class="exercice-sandbox">
<?php
if (str_contains($text1, $nameProduct1)) {
echo "<li>$nameProduct1</li>";
}
if (str_contains($text1, $nameProduct2)) {
echo "<li>$nameProduct2</li>";
}
if (str_contains($text1, $nameProduct3)) {
echo "<li>$nameProduct3</li>";
}
?>
</div>
</section>
<!-- QUESTION 6 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 6</h2>
<p class="exercice-txt">Parmis les scores suivants, affichez le prénom des joueurs qui ont obtenus entre 50 et 150 points.</p>
<div class="exercice-sandbox">
<?php
$namePlayer1 = "Tim";
$scorePlayer1 = 67;
$namePlayer2 = "Morgan";
$scorePlayer2 = 198;
$namePlayer3 = "Hamed";
$scorePlayer3 = 21;
$namePlayer4 = "Camille";
$scorePlayer4 = 134;
$namePlayer5 = "Kevin";
$scorePlayer5 = 103;
if (50 <= $scorePlayer1 && $scorePlayer1 <= 150) {
echo "<li>$namePlayer1</li>";
}
if (50 <= $scorePlayer2 && $scorePlayer2 <= 150) {
echo "<li>$namePlayer2</li>";
}
if (50 <= $scorePlayer3 && $scorePlayer3 <= 150) {
echo "<li>$namePlayer3</li>";
}
if (50 <= $scorePlayer4 && $scorePlayer4 <= 150) {
echo "<li>$namePlayer4</li>";
}
if (50 <= $scorePlayer5 && $scorePlayer5 <= 150) {
echo "<li>$namePlayer5</li>";
}
?>
</ul>
</div>
</section>
<!-- QUESTION 7 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 7</h2>
<p class="exercice-txt">En réutilisant les scores de la question pécédente, afficher le nom du joueur ayant obtenu le plus grand score.</p>
<div class="exercice-sandbox">
<?php
$maxScore = 0;
$winnerName = '';
$scores = [$scorePlayer1, $scorePlayer2, $scorePlayer3, $scorePlayer4, $scorePlayer5];
$names = [$namePlayer1, $namePlayer2, $namePlayer3, $namePlayer4, $namePlayer5];
for ($i = 0; $i < sizeof($scores); $i++) {
if ($scores[$i] > $maxScore) {
$maxScore = $scores[$i];
$winnerName = $names[$i];
}
}
echo "<p>Le gagnant est: $winnerName</p>";
?>
</div>
</section>
<!-- QUESTION 8 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 8</h2>
<p class="exercice-txt">Affichez le prénom du joueur le plus long en nombre de caractères.</p>
<div class="exercice-sandbox">
<?php
$countLetters = 0;
$longestName = '';
$names = [$namePlayer1, $namePlayer2, $namePlayer3, $namePlayer4, $namePlayer5];
for ($i = 0; $i < sizeof($names); $i++) {
if (strlen($names[$i]) > $countLetters) {
$countLetters = strlen($names[$i]);
$longestName = $names[$i];
}
}
echo "$longestName";
?>
</div>
</section>
<!-- QUESTION 9 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 9</h2>
<p class="exercice-txt">Créer une variable $players ayant pour valeur un tableau multidimensionnel contenant toutes les données des joueurs avec leurs scores ci-dessus et leurs ages ci-dessous.</p>
<ul class="exercice-txt">
<li>Tim : 25 ans</li>
<li>Morgan : 34 ans</li>
<li>Hamed : 27 ans</li>
<li>Camille : 47 ans</li>
<li>Kevin : 31 ans</li>
</ul>
<p class="exercice-txt">Afficher la valeur de cette variable avec tous les détails.</p>
<div class="exercice-sandbox">
<?php
$players = [
["name" => $namePlayer1, "score" => $scorePlayer1, "age" => 25],
["name" => $namePlayer2, "score" => $scorePlayer2, "age" => 34],
["name" => $namePlayer3, "score" => $scorePlayer3, "age" => 27],
["name" => $namePlayer4, "score" => $scorePlayer4, "age" => 47],
["name" => $namePlayer5, "score" => $scorePlayer5, "age" => 31],
];
foreach ($players as $nb => $infos) {
echo 'User n°' . ($nb + 1) . ' :<br>';
foreach ($infos as $c => $v) {
echo $c . ' : ' . $v . '<br>';
}
echo '<br>';
}
// var_dump($players);
?>
</div>
</section>
<!-- QUESTION 10 -->
<section class="exercice">
<h2 class="exercice-ttl">Question 10</h2>
<p class="exercice-txt">Afficher le prénom et l'âge du joueur le plus jeune dans une phrase dans une balise HTML P.</p>
<div class="exercice-sandbox">
<?php
// $ageYounger = 100;
// for ($i = 0; $i < sizeof($players); $i++) {
// if ($players[$i]['age'] < $ageYounger) {
// $ageYounger = $players[$i]['age'];
// $youngerPlayer = $players[$i]['name'];
// }
// }
// echo "<p> Le joueur le plus jeune est $youngerPlayer et son âge est de $ageYounger. </p>";
for ($i = 0; $i < sizeof($players); $i++) {
if (!isset($youngerIndex) || $players[$i]['age'] < $players[$youngerIndex]['age']) {
$youngerIndex = $i;
}
}
echo "<p> Le joueur le plus jeune est {$players[$youngerIndex]['name']} et son âge est de {$players[$youngerIndex]['age']}. </p>";
foreach ($players as $player) {
if (!isset($ageYounger2) || $player['age'] < $ageYounger2) {
$ageYounger2 = $player['age'];
$nameYounger2 = $player['name'];
}
}
echo "<p> Le joueur le plus jeune est {$nameYounger2} et son âge est de {$ageYounger2}. </p>";
?>
</div>
</section>
</div>
<?php
require 'footer.php';
?>
</body>
</html>