-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import PhpPractice from "@/components/practice/PhpPractice"; | ||
import Enonce from "../../Enonce"; | ||
import Anchor from "@/components/utils/Anchor"; | ||
|
||
const initialCode = `<?php | ||
$users = ['Amanda', 'Annie', 'Georgie', 'Victoria', 'Virgie', 'Ellen', 'Calvin']; | ||
`; | ||
|
||
const Hint = () => ( | ||
<div> | ||
Pour afficher les éléments dans l'ordre inverse, vous devez partir du | ||
dernier élément. | ||
<br /> | ||
L'index du dernier élément est donc{" "} | ||
<span className="bg-blue-500 dark:bg-gray-700 p-1 font-bold"> | ||
count($users) - 1 | ||
</span> | ||
</div> | ||
); | ||
|
||
const WhileLoop = () => { | ||
const checkCode = (code: string) => code.match(/while\s*\(/) !== null; | ||
|
||
const checkResult = (output: string[]): boolean => { | ||
return ( | ||
output.length === 7 && output[0] === "Calvin" && output[6] === "Amanda" | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="mb-8"> | ||
<h3 className="text-lg mb-2 font-bold uppercase" id="while-loop"> | ||
Utiliser la boucle while <Anchor id="while-loop" /> | ||
</h3> | ||
<Enonce> | ||
Affichez tous les éléments de ce tableau à l'aide d'une boucle | ||
while, <strong>mais en partant de la fin</strong>. | ||
<br /> | ||
<strong> | ||
Affichez un utilisateur par ligne : utilisez la constante{" "} | ||
<span className="bg-slate-300 dark:bg-slate-800 p-1">PHP_EOL</span>{" "} | ||
pour revenir à la ligne | ||
</strong> | ||
<br /> | ||
Vous devez afficher les éléments en sens inverse. | ||
<br /> | ||
Pour valider, le premier prénom qui devra apparaître sera donc | ||
"Calvin" et le dernier "Amanda" | ||
</Enonce> | ||
<PhpPractice | ||
initialCode={initialCode} | ||
hint={<Hint />} | ||
checkCode={checkCode} | ||
checkOutput={checkResult} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WhileLoop; |