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

Kristina Liburd
Kristina Liburd
1,599 Points

Getting only a portion of the question displayed

I've been able to complete the majority of the challenge - however for some reason I am unable to see the full question displayed. It only shows the first letter of the question. I can see how many I've answered correctly and it will show the number of correct and incorrect questions but I cannot see the actual question. I am completely baffled.

var questions = [ ['How many kids does Beyonce have', 3], ['How many Asian women have won Best Supporting Actress at the Golden Globes?', 1], ['How many times has Priyanka Chopra been married?', 2] ];

var answer; var question; var response; var html; var score = 0; var correctQuestions = []; var incorrectQuestions = [];

function makeList( list ) { var listHTML = '<ol>'; for ( var i = 0; i < list.length; i += 1) { listHTML += '<li>' + list[i][0] + '</li>'; } listHTML += '</ol>'; print(listHTML); }

function print(message) { document.write(message); }

for (i=0; i < questions.length; i+=1) { question = questions[i][0]; answer = questions[i][1]; response = prompt(question); response = parseInt(response); if ( response === answer) { scores += 1; correctQuestions.push(question) } else { incorrectQuestions.push(question) } }

html = 'You got '+ score + ' correct!'; print(html);

print('<h3>'+ 'These are the questions you got correct' + '</h3>') makeList(correctQuestions);

print('<h3>'+ 'These are the questions you got incorrect' + '</h3>') makeList(incorrectQuestions);

1 Answer

In your loop in makeList() you have

listHTML += '<li>' + list[i][0] + '</li>'; 

This will retrieve the first character of list[i]. It should just be:

listHTML += '<li>' + list[i] + '</li>'; 

Also you defined variable score but then use scores += 1 when checking if the response equals the answer.