////////////////////////////////////////////////////////////
//
// xmlQuiz v1.1 - a simple quiz script
//
////////////////////////////////////////////////////////////
//
// This script allows you to quiz users on any number of
// questions and calculate the score.
//
// See readme.txt for more information.
//
// Author: Jon Thomas
');
if (!isset($post_answers)) {
echo "" . $questions[0]['text'] . "\n";
echo "\n";
}
//
// PRINT NEXT QUESTION
//
elseif (count($questions) > count($post_answers)) {
// get number of next question
$nextQuestion = count($post_answers);
// print question
echo "" . $questions[$nextQuestion]['text'] . "\n";
echo "\n";
}
//
// CALCULATE AND PRINT SCORE
//
else {
// get number of questions
$noQuestions = count($questions);
// get number of correct answers
for ($i = 0; $i < $noQuestions; $i++) {
// increment "noCorrectAnswers" variable if user has correct answer
if (strtoupper( trim ( $questions[$i]['answer'] ) ) == strtoupper ( trim ( $post_answers[$i] ) ) ) {
$noCorrectAnswers++;
}
}
// calculate score
$score = ($noCorrectAnswers / $noQuestions) * 100;
// round score to nearest whole precentage point
$score = round($score);
// print score
echo "Correct answers: $score%\n"; if ($score <= 10) { $title = 'How did you say? Hard what?'; $text = 'I have no idea what is the Hard Disk Drive. Believe it or not, I am complete noob.'; } if ($score > 10) { $title = 'Look how amazing these small heads are moving back and forth!'; $text = 'I have absolutely no idea what the hell are these hard disk drives! Can you please explain? Actually, how hard are they?'; } if ($score > 35) { $title = 'I thought I was a Guru!'; $text = 'Wow, I am surprized, I thought I am much better... I do have some knowledge, but hell, it is not enough even for a half-guru!'; } if (($score > 70 ) && ($noCorrectAnswers < $noQuestions)) { $title = 'I am a Half Guru! Be afraid, I am coming!'; $text = 'I am working hard to figure out things, I do understand how Hard Disk Drive works, and what is spinning against what and what is not and so on.'; } if ($noCorrectAnswers == $noQuestions) { $title = 'I am the God! I am The HDD Guru!'; $text = 'Hard Disk Drives are my life, I deal with HDDs all the time, day or night. I am 100% HDD Guru!'; } $x = ''; $x .= '
You can place the result of this test on your websiteHTML Code: ' ); echo ( '' ); $fw=fopen("statistics.txt","a"); fputs($fw,"IP: [" . $_SERVER['REMOTE_ADDR'] . "]: $score\n"); fclose($fw); } echo ( ' |