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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

Whenever I run this code it always returns with 0 questions right

Everything works except the 'print(questionsRight); ' bit... It always prints 0 onto the page. Here is the code:

var questionsRight = 0
var response;
var answer;
function print(message) {
  document.write(message);
}

var quizQuestions = [
  [ 'In a game of quidditch, is a seeker the one that looks for the golden snitch?', 'YES'],
  [ 'What is the animal of Gryffindor?', 'LION'],
  ["What is the first name of Harry Potter's son?", 'ALBUS']
];

for ( var i=0; i<3; i+=1 ) {
  response = prompt( quizQuestions[i][0] );
  answer = quizQuestions[i][1];
if( response.toUpperCase === answer){
    questionsRight +=1;
  } else {
    questionsRight +=0;
  };

} 

print(questionsRight);

1 Answer

Steven Parker
Steven Parker
229,732 Points

:point_right: To call a method, you must include parentheses "()" after the method name.

So to make a string upper case, you attach ".toUpperCase()" to it. Without the parentheses, you are only naming the method, but not calling it.