Malvina
08-01-2003, 11:19 PM
I am attempting to implement a java script quiz. Have it working but am unable to determine how to reset the radio buttons so that someone can clear the form and try again. I am able to return the score to zero but haven't a clue how to reset the buttons. I'm obviously a novice and would appreciate help.
I'm using a script from the site and modifying as necessary. Here is the script and also the reset "onclick" code.
<!-- Begin
var ans = new Array;
var done = new Array;
var yourAns = new Array;
var explainAnswer = new Array;
var score = 0;
ans[1] = "b";
ans[2] = "b";
ans[3] = "a";
ans[4] = "b";
ans[5] = "a";
explainAnswer[1]="False";
explainAnswer[2]="False";
explainAnswer[3]="True";
explainAnswer[4]="False";
explainAnswer[5]="True";
function Engine(question, answer) {
yourAns[question]=answer;
}
function Score(){
var answerText = "How did you do?\n------------------------------------\n";
for(i=1;i<=5;i++){
answerText=answerText+"\nQuestion :"+i+"\n";
if(ans[i]!=yourAns[i]){
answerText=answerText+"The correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
}
else{
answerText=answerText+"Correct! \n";
score++;
}
}
answerText=answerText+"\n\nYour total score is : "+score+"\n";
//now score the user
answerText=answerText+"\nComment : ";
if(score<=0){
answerText=answerText+"Contact FedReady";
}
if(score>=1 && score <=2){
answerText=answerText+"Contact FedReady";
}
if(score>=3 && score <=3){
answerText=answerText+"Contact FedReady";
}
if(score>=4){
answerText=answerText+"Congratulations";
}
alert(answerText);
}
function Reset(){
score = 0;
}
// End -->
</script>
<input type=button onClick="Reset()" value="Start Over" >
I'm using a script from the site and modifying as necessary. Here is the script and also the reset "onclick" code.
<!-- Begin
var ans = new Array;
var done = new Array;
var yourAns = new Array;
var explainAnswer = new Array;
var score = 0;
ans[1] = "b";
ans[2] = "b";
ans[3] = "a";
ans[4] = "b";
ans[5] = "a";
explainAnswer[1]="False";
explainAnswer[2]="False";
explainAnswer[3]="True";
explainAnswer[4]="False";
explainAnswer[5]="True";
function Engine(question, answer) {
yourAns[question]=answer;
}
function Score(){
var answerText = "How did you do?\n------------------------------------\n";
for(i=1;i<=5;i++){
answerText=answerText+"\nQuestion :"+i+"\n";
if(ans[i]!=yourAns[i]){
answerText=answerText+"The correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
}
else{
answerText=answerText+"Correct! \n";
score++;
}
}
answerText=answerText+"\n\nYour total score is : "+score+"\n";
//now score the user
answerText=answerText+"\nComment : ";
if(score<=0){
answerText=answerText+"Contact FedReady";
}
if(score>=1 && score <=2){
answerText=answerText+"Contact FedReady";
}
if(score>=3 && score <=3){
answerText=answerText+"Contact FedReady";
}
if(score>=4){
answerText=answerText+"Congratulations";
}
alert(answerText);
}
function Reset(){
score = 0;
}
// End -->
</script>
<input type=button onClick="Reset()" value="Start Over" >