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

Ernest Son
Ernest Son
13,532 Points

counter always reports "all were right" when not so....

//use 2-d array to hold question-answer
var questions = [
                ["What is the capital of Georgia, USA?", "Atlanta"],
                ["How do you spell fart backwards?", "tarf"],
                ["What is the programming language that is abbreviated with js?", "JavaScript"],
                ["Who is the current president of the United States?","Barack Obama"],
                ["Who is the actor who played Batman in the original Batman TV series","Adam West"],
var correctAnswers = 0;
var question;
var response;
var answer;
var html;

//add functions here
function print(message) {

//create a loop, ask 5 questions and compare to answer
for ( var i=0; i < questions.length ; i++ ) {
      question = questions[i][0];
      answer = (questions[i][1]).toLowerCase;
     //use the prompt method to ask question i
     response = (prompt(question)).toLowerCase;
     //compare to the right answer with an if statement
     if (response === answer) {  
     //add to correctAnswers
       correctAnswers += 1;


html = "You got " + correctAnswers + " question(s) right!";

the message always says there were 5 correct answers.....

Ernest Son
Ernest Son
13,532 Points

I did fix the fart answer...;-)

1 Answer

Ernest Son
Ernest Son
13,532 Points

nevermind....figured it out.....toLowerCase()