Geography: countries and their capitals
Solution
....- Given is an associative array
$capitals
with countries (keys) and their capitals (values) - Generate a random country
- Add a select list with all possible answers (capitals sorted alphabetically)
- Submit your answer (to the same page) when clicking the button, and show some feedback:
- When no capital is selected: Please choose a city! in a
div
with classbox-warning
- When a wrong capital is selected: "Wrong: the correct answer is ... in a
div
with classbox-warning
- When the correct capital is selected: Correct! in a
div
with classbox-primary
- When no capital is selected: Please choose a city! in a
Tip
- The random country can be generated with the function
array_rand()
, which generates a random key of an array, on the given array$capitals
- Use a hidden field (
type="hidden"
) to pass the value of this random country along with your GET or POST request