JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2 Solution

Kristina Liburd
Kristina Liburd
Full Stack JavaScript Techdegree Student 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.