|
Calculate score problem
I'm trying to create a javascript quiz where users have to type the correct numbers in boxes, one of which is to be left blank.
In the example there are 3 boxes, and the correct answer is 3 in the first box and 2 in the last. The middle box is to be left blank.
When the boxes are filled in correctly, there is a visual and audible response.
If I set the value of the blank box to "" (i.e. none), the script works fine; but there is a problem: if the user clicks the check button, he/she can see which is the blank and the quiz is much easier.
This can be solved by setting the value of the blank to " " (i.e. a space). There is then no visual clue if the user clicks Check before starting the quiz - fine, that's what I want.
But this means that the Check function will not be able to arrive at 100%, since the user's input in the blank box does not correspond to the hidden value.
So what I need is to change the calculate score script so it ignores the value in the blank box.
Can anyone help? I would be very grateful.
<table id="tab1" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td width="50"><input type="hidden" value="3"><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>
<td width="50"><input type="hidden" value=""><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>
<td width="50"><input type="hidden" value="2"><input type="text" style="border:1px solid;text-align:center;" size="1"><span></span></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2">
<tr><td>
<form id="f"><input type="button" value="Check" onclick='Check()'></form>
</td></tr>
</table>
<script type="text/javascript">
function playSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
var TPoint=0;
function Check() {
TPoint=0;
var total=document.getElementById("tab1").getElementsByTagName("input").length/2;
var e=0;
var draw = document.getElementsByTagName("span");
var inputs = document.getElementsByTagName("input");
for (var i=0;i<inputs.length;i++)
if ( inputs.item(i).type=="text")
{
if (trim(inputs.item(i).value)==inputs.item(i-1).value)
{
(draw.item(e)).style.fontFamily="Wingdings";
(draw.item(e)).innerHTML="\u00FC";
TPoint++;
}
else if (inputs.item(i).value != "")
{
(draw.item(e)).style.fontFamily="Wingdings";
inputs.item(i).value="";(draw.item(e)).innerHTML="\u00FB";
};
e++;
}
TPoint=Math.round(100*TPoint/total)
if (TPoint==100)
document.right.play();
else
document.wrong.play();
}
function trim(s){
return s.replace(/^\s+/,'').replace(/\s+$/,'');
}
</script>
<!-- SOUND ON CORRECT ANSWER -->
<embed src="right.mp3" autostart=false hidden=true name="right"
enablejavascript="true"></embed>
<!-- SOUND ON INCORRECT ANSWER -->
<embed src="wrong.mp3" autostart=false hidden=true name="wrong"
enablejavascript="true"></embed>
|