Untitled
unknown
plain_text
a year ago
999 B
8
Indexable
<?php
$correct_answers = array(
"q1" => "Au",
"q2" => "Ag",
"q3" => "Cu",
"q4" => "O",
"q5" => "H"
);
$user_answers = array(
"q1" => ($_POST['q1']),
"q2" => ($_POST['q2']),
"q3" => ($_POST['q3']),
"q4" => ($_POST['q4']),
"q5" => ($_POST['q5']),
);
$questions = array(
"q1" => "1. What is the symbol for Gold?",
"q2" => "2. What is the symbol for Silver?",
"q3" => "3. What is the symbol for Copper?",
"q4" => "4. What is the symbol for Oxygen?",
"q5" => "5. What is the symbol for Hydrogen?",
);
$score = 0;
foreach ($questions as $key => $Question) {
echo "Question: $Question <br>";
echo "Your Answer is: ".$user_answers[$key]. ".<br><br>";
if($user_answers[$key]===$correct_answers[$key]){
echo "<b>Correct! </b><br><br>";
$score++;
} else {
echo "<b> Incorrect! </b>";
echo "The correct answer is ".$correct_answers[$key].".<br><br>";
}
}
echo "<strong> Your total score is $score out of 5</strong>";Editor is loading...
Leave a Comment