Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUIZ WITH 2 OR MORE POSSIBLE ANSWERS ! 1

Status
Not open for further replies.

melstef

Programmer
Feb 19, 2003
69
0
0
CA
here is my script, how can I write the script to have more than one possible answers?:
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var ans = new Array;
var done = new Array;
done[1] = false;
done[1] = false;
done[3] = false;
done[4] = false;
done[5] = false;
done[6] = false;
done[7] = false;
done[8] = false;
done[9] = false;
done[10] = false;


var score = 0;
ans[1] = "a";
ans[1] = "c";
ans[3] = "c";
ans[4] = "c";
ans[5] = "c";
ans[6] = "a";
ans[7] = "b";
ans[8] = "d";
ans[9] = "b";
ans[10] = "b";



function Engine(question, answer)
{
if (answer != ans[question])
{
if (done[question] == false)
{
alert("Nope. Your score stays at " + score+" points.");
}
else
{
alert("You have already answered this one.");
document.getElementById("quest"+question+"-"+ans[question]).checked = true;
}
//if(done[question] && )
/*else
{
alert("You have already answered this one.");
}*/
}

else
{
if (done[question] == false)
{
done[question] = true;
score++;
alert("Yes! Your score is now " + score+" points.");
}

else
{
alert("You have already answered this one.");
}
}
}




// End -->
</SCRIPT>
 
ans[1] = "a,d";
ans[2] = "c";
ans[3] = "c";
ans[4] = "c,d";
ans[5] = "c";
ans[6] = "a,b,c";
ans[7] = "b";
ans[8] = "d";
ans[9] = "b";
ans[10] = "b";
...
...
...

if (ans[question].indexOf(answer) == -1){
// incorrect answer
}


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
I'm sorry, I'm not used to the javascript..
Where should I put the string in my code:
if (ans[question].indexOf(answer) == -1){
// incorrect answer
}

Thanks
 
function Engine(question, answer)
{
if (answer != ans[question])


becomes

function Engine(question, answer)
{
if (ans[question].indexOf(answer) == -1)

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top