0

I am creating a quiz in which I don't want the same question to pop up twice. If that happens, I want the page to update. So every time a question comes, the correct answer of the question will be put in a hidden div called #hiddencounter, with the following code:

 $("#hiddencounter").append($("#correctans").html());

I now want to be able to update the page if two of the same answers suddenly appears in the #hiddencounter, or if there is a code that makes the append function recognize if it adds two of the same text strings?

Help is greatly appreciated!

user1890129
  • 7
  • 1
  • 3
  • Sorry but can't two questions have same answer ? Detecting duplicates based on question may be better than based on answers. – Biswanath Apr 30 '13 at 11:13

1 Answers1

1

If you want to search occurrance of a string in another string, you can follow this link: https://stackoverflow.com/a/1789952/1584494

In your case, you can use:

if($("#hiddencounter").html().indexOf($("#correctans").html()) >= 0){
  // case already exists
}else{
  // case not yet exists
}
Community
  • 1
  • 1
sreng
  • 153
  • 3