Code Help, Please

  • Thread starter Thread starter Teach
  • Start date Start date
T

Teach

I am designing a small quiz, and everything works just fine except one
small problem. If a user inputs any uppercase letters at all, the
check function marks the response incorect. Below is the snippet of
code for the function check. Can anyone tell me how to modify it to
ignore "case". The user needs to be able to input in both upper and
lower case.

Thanks in advance. Here is the snippet of code:

function check(){

for(i=0;i<answer.length;i++){
if(document.myform.elements.value.toLowerCase()==answer){
score++;
}else{
if(document.myform.elements.value!=""){
document.myform.elements.value="";
}
}

}
alert(score + " out of " + answer.length + ".");
score = 0;
}

//Put the correct answers into all the fields

function show(){

for(i=0;i<answer.length;i++){
document.myform.elements.value = answer;
}

}
 
Set the answer to lowercase also...
if(document.myform.elements.value.toLowerCase()==answer.toLowerCase())
{
score++;
}

Bob Lehmann
 
Thank you very much for your help and assistance Bob. It worked perfectly.
Set the answer to lowercase also...
if(document.myform.elements.value.toLowerCase()==answer.toLowerCase())
{
score++;
}

Bob Lehmann

Teach said:
I am designing a small quiz, and everything works just fine except one
small problem. If a user inputs any uppercase letters at all, the
check function marks the response incorect. Below is the snippet of
code for the function check. Can anyone tell me how to modify it to
ignore "case". The user needs to be able to input in both upper and
lower case.

Thanks in advance. Here is the snippet of code:

function check(){

for(i=0;i<answer.length;i++){
if(document.myform.elements.value.toLowerCase()==answer){
score++;
}else{
if(document.myform.elements.value!=""){
document.myform.elements.value="";
}
}

}
alert(score + " out of " + answer.length + ".");
score = 0;
}

//Put the correct answers into all the fields

function show(){

for(i=0;i<answer.length;i++){
document.myform.elements.value = answer;
}

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top