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 trialKristina Liburd
1,599 PointsGetting 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
KRIS NIKOLAISEN
54,971 PointsIn 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.
Kristina Liburd
1,599 PointsKristina Liburd
1,599 PointsThanks for this!