Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-03-2005, 11:20 AM   PM User | #1
jerryman
New to the CF scene

 
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jerryman is an unknown quantity at this point
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>
jerryman is offline   Reply With Quote
Old 06-04-2005, 05:41 AM   PM User | #2
devosc
New Coder

 
Join Date: Jun 2005
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
devosc is an unknown quantity at this point
I might be way off base, but if you simply do not want to check when user clicks check prior to entering anything then just add a text to make sure i != 3 in the first winding if statement...

Presumably the others errors and correpsonding outputs are sufficient such that it is not just a one click too see the expected answer as per Q...

Hmm.. not sure what the status quo is here since I'm new my self, but couple of suggestions, are, formatting, and then presenting Q in simpliest / plain methods ( i.e lose the windings...).

Also, even though it took me a few mins to work out the fancy javascript calculation it dawned on me that the answers are plainly there in the hidden elements, so couldn't the javascript been a bit more straight forward ... anyway probably because I didn't start from scratch etc...

G.
devosc is offline   Reply With Quote
Old 06-04-2005, 11:11 AM   PM User | #3
jerryman
New to the CF scene

 
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jerryman is an unknown quantity at this point
Thanks for the suggestions. I'm working on it ...
jerryman is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:05 AM.


Advertisement
Log in to turn off these ads.