0

I'm trying to learn Javascript before I learn jQuery so I can get the foundation down before moving up.

To learn, I've made a simple guessing game that works in Chrome & Safari, but not Firefox. (I guess that is why people use jQuery!).

I adjusted the code based on this answer. But it is still not working in Firefox. Here's the relevant code. Any ideas?

function reportAnswer(e) {
  if(!e) e = window.event;
  questionNumber++;
  document.getElementById("myCount").innerHTML = (questionNumber + 1);
  var x = e.target || e.srcElement;
  checkAnswer();
}

function checkAnswer() {
  var thisAnswer = questionDatabase[currentQuestion].answer;
  if(event.target.id == thisAnswer) {
    document.getElementById("answer").innerHTML = ("YES! </br>" + questionDatabase[currentQuestion].photo);
    score++;
  }
  else {
    document.getElementById("answer").innerHTML = ("<img src=http://philly.barstoolsports.com/files/2012/11/family-feud-x2.png width='370' height='370'>");
  }
}
Community
  • 1
  • 1

1 Answers1

1

Your checkAnswer function uses the nonstandard global window.event. You want to do two things:

  1. Add an event or e argument to it like @thesystem suggests.
  2. Make sure to pass that argument in from whatever your event handler is.
Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55