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 trial

JavaScript Object-Oriented JavaScript (2015) Practice Project User Interface Code

Can'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

Your 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

More typos

function Quiz(questions) {
  this.score = 0;
  this.questions = questions;
  this.currentQuestionIndex = 0;

}
// should be function not fucntion
Quiz.prototype.guess = fucntion(answer){
  if(this.getCurrentQuestion().isCorrectAnswer(answer)){
    this.score++;
  } // < Need a semi colon here
  this.currentQuestionIndex++;

Quiz.prototype.getCutrrentQuestion = function(){
  return this.questions[this.currentQuestionIndex];
};

Quiz.prototype.hasEnded = function() {
  return this.currentQuestionIndex >= this.questions.length;
};

Thanks 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

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 
      });
    }
  }

Other 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?

yes 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.

https://w.trhou.se/bmje9c98c0