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 PointsCan't figure out what is wrong with my code . Please help! ..giving errors
I seem to be not good at debugging and finding out what's wrong with my code and what to fix. If anyone could please take a look and help me
Snapshot- https://w.trhou.se/jyk60915z7
3 Answers
Dale Bailey
20,269 PointsYour question.js has a typos you need to be a little more specific to what the problem may be?
function Question(text,choices,answer) {
this.text = text;
this.choices = choices;
this.answer = answer;
}
// typos here should be Question not Quesiton and should be function not funtion
Quesiton.prototype.isCorrectAnswer = funtion() {
return this.answer === choice;
};
Hope that helps
Kenneth Black
23,140 PointsI 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
});
}
}
Kenneth Black
23,140 PointsOther than the aforementioned typos, you're also missing a closing bracket to your guess function, though looking at your workspaces you seem to have corrected that as well. Are you having any more errors?
Sunny Singh
1,148 Pointsyes it's saying a error that button is not defined , even though it is . Also not sure why my quiz questions is not displaying . If you could please take a look.
Dale Bailey
20,269 PointsDale Bailey
20,269 PointsMore typos
Sunny Singh
1,148 PointsSunny Singh
1,148 PointsThanks for catching typos but I am getting unexpected number error
//error 1
question.js:7 Uncaught SyntaxError: Unexpected token {
//error2
app.js:3 Uncaught SyntaxError: Unexpected number
https://w.trhou.se/7uxfu6dnqg