Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Quiz.prototype.guess question about parameter

I keep getting crossed up when reading the guess function. Can anyone clarify my understanding? The guess function has 1 parameter, which is argument, which is passed into the isCorrectAnswer(choice) function as an argument when we call it from the question.js file.

Where I keep getting crossed up is, why are we using answer in the guess function, and choice in the isCorrectAnswer function? Is there a reason for this? Wouldn't it make more sense to use choice for both? Or even answer for both? Since a choice is an answer, and an answer is a choice? I tried it this way and it works.

I think I'm getting crossed up because there are so many pieces to this equation, it can be mind-boggling. Any feedback is appreciated. Thanks in advance!

quiz.js file

Quiz.prototype.guess = function(choice) {
    if(this.getCurrentQuestion().isCorrectAnswer(choice)) {

question.js file

Question.prototype.isCorrectAnswer = function (choice) {
    return this.answer === choice;

1 Answer

Steven Parker
Steven Parker
217,626 Points

The main thing to keep in mind here is that when you define a function, the parameter name is only a placeholder for the real value that will be used when the program runs. The parameter name has no bearing on program operation, it could be "joe" or "noodle" or "uq42" and it would make no difference. It only needs to be used consistently within the function.

But for clarity, a name is usually chosen based on what the parameter will be used for in the function. While "answer" would have been appropriate in both cases, "choice" was probably used in the latter function to eliminate confusion when it is compared to the "answer" property of the Question object.

Thanks again Steven! I'm understanding but guess it takes some getting use to until I'm more comfortable with it.