input answer quiz -

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

input answer quiz -

Postby vincerosso » Wed Apr 25, 2007 8:17 am

HI

I have tried to make the input answer quiz a little more tolerant by changing the answer comparison code.

I am not very experienced at PHP so I apologize in advance if I have made any 'rookie' mistakes.

Needless to say my modified Quiz produces no output...

Could anyone tell me what I have done wrong??

---------------------------------------------------------------------
I have changed (in quiz.php)

if(strtolower($user_answer) == strtolower($actual_answer))

to

if(inStr(strtolower($actual_answer), strtolower($user_answer))


and I have added the 'instring' function (in \includes\functions.quiz.php

function inStr ($needle, $haystack)
{
$needlechars = strlen($needle); //gets the number of characters in our needle
$i = 0;
for($i=0; $i < strlen($haystack); $i++) //creates a loop for the number of characters in our haystack
{
if(substr($haystack, $i, $needlechars) == $needle) //checks to see if the needle is in this segment of the haystack
{
return TRUE; //if it is return true
}
}
return FALSE; //if not, return false
}
vincerosso
Greenhorn
Greenhorn
 
Posts: 4
Joined: Fri Apr 20, 2007 10:50 am

Postby battye » Wed Apr 25, 2007 9:00 am

Are you trying to allow more answers, for instance:

The real answer is "Beatles", but someone inputs "The Beatles" and have it seen as a correct answer? I assume that is what you want to achieve by checking for the needle in a haystack.
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14264
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe

Postby vincerosso » Thu Apr 26, 2007 5:37 pm

battye wrote:Are you trying to allow more answers, for instance:

The real answer is "Beatles", but someone inputs "The Beatles" and have it seen as a correct answer? I assume that is what you want to achieve by checking for the needle in a haystack.


Thats correct.....

is my code correct because all I get is a blank screen when I modify the code.....
vincerosso
Greenhorn
Greenhorn
 
Posts: 4
Joined: Fri Apr 20, 2007 10:50 am


Return to Web Design

Who is online

Users browsing this forum: No registered users and 1 guest

cron