Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSunny Singh
1,148 PointsMy quiz is not displaying ? Please help!
Also it's giving error - button not defined
Snapshot - https://w.trhou.se/bmje9c98c0
1 Answer
Kenneth Black
23,140 Pointsfrom my response on your other question:
I don't see button defined, but probably more importantly, you don't want to be handling buttons inside your populateIdWithHTML function, which should just look like this:
populateIdWithHTML: function(id, text) {
var element = document.getElementById(id);
element.innerText = text;
}
Then, you want to add the event handlers inside the displayChoices function, like so:
displayChoices: function() {
var choices = quiz.getCutrrentQuestion().choices;
for (var i = 0; i < choices.length; i++) {
this.populateIdWithHTML("choice" + i, choices[i]);
var button = document.getElementById('guess' + i);
button.addEventListener("click", function() {
// put whatever you want it to do on button press here
});
}
}