I'm creating a game that displays images, and if the player clicks on the image, a function is called to update the stats (score/correct answers/incorrect answers). I've stored the images in an array, and within the update stats function I compare the player's answer (image selected) with the array. However, no matter whether correct or not, the player's answer is always classed as wrong and they never get any correct answers.
Could somebody please check out my code to see if they can spot any obvious errors. Much appreciated.
function displayImgs () {
for(i = 0; i < allCelebs.length; i++){
document.getElementById("image"+i).src = fullList[i];
}
}
function updateStats () {
Answer = document.getElementById("image"+i);
var counter = 0;
while (counter < selectedImages.length) {
if (Answer==selectedImages[counter]) {
score+=50;
correctAnswers+=1;
} else {
score-=20;
incorrectAnswers+=1;
}
counter++;
}
}
And my code for generating the images in html:
<script>
for (count=0;count<16;count++) {
document.write("<img id='image",count,"' src='blank.jpg' onClick='updateStats();'>");
}
</script>
iin updateStats ??function updateStats ( i ) {andonClick='updateStats( count )? :-)