-1

am basically looking for a way in jquery where my script will wait 15seconds or so, and display a correct ans if the user hasnt selected an answer already. at the moment it just seems to run straight through. ps this method is called in a for loop, with other methods/functions so it runs straight through iterating through the array. thr for loop is placed below although appears further up in the actual script. to be clear am looking for a wa for the script to check if within those 15seconds the user has clicked a button. at the moment its not even doing that. there are about 10 items in the array, but once the start button is clicked to start the quiz it iterates straight through right to the last item, so the user doesnt even get to make a choice. setTimeout i dont think i appropriate here...tried it but theres a huge poss i cld be wrong

function getUserResp(){
 $("#countdown").countdown({seconds: 15});
 setTimeout("dispAns()", 16000);
 $("#ans1").click(function(){
 ansStr=$(this).text();
 checkAns(ansStr);
 }); 
 $("#ans2").click(function(){
 ansStr=$(this).text();
 checkAns(ansStr);
 }); 
 $("#ans3").click(function(){
 ansStr=$(this).text();
 checkAns(ansStr);
 });
 $(".ans").mouseover(function(){
 $(this).addClass("hilite").fadeIn(800);
 }); 
 $(".ans").mouseout(function(){
 $(this).removeClass("hilite");
 });
}
 $.each(qArr, function(i){
 getAns(i);
 getQuestion(i);
 presentData();
 getUserResp();
 displayAnsResp();
 });
 getTotalScore();
 });
Nick Craver
631k138 gold badges1.3k silver badges1.2k bronze badges
asked Aug 18, 2010 at 17:10
2
  • possible duplicate of javascript, while loop Commented Aug 18, 2010 at 17:35
  • Stack Overflow isn't like a forum. Please do not post duplicate questions. You can always edit or add commentary to your original question. Commented Aug 18, 2010 at 17:35

1 Answer 1

2

setTimeout is the way to go,. you can have the function called after 15 seconds using setTimeout and then the function should check if any button has been pressed,. if no it should display the answer,,. you can set a flag to true when any button is clicked and then check that flag in the displayanswer function

answered Aug 18, 2010 at 17:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.