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 2 Solution

rocky roy
rocky roy
556 Points

Why my code is not working i have written everything same.

What is connection between BuildList() function with Print() function, i am very confused about it. i don't see any connection between them so how it will work. what DEEV show in the tutorial it's like magic. is there anyone who can explain me how it's working ?

And here is my code :- it's not working i wrote the same thing which i saw in the tutorial but i just changed the variable name.

var CorrectAnswer = 0; var WrongAnswer = 0; var AskQuestion; var Attemps = 0; var PrintAnswer = ''; var allQuestion = [ ['The capital of India', 'DELHI'], ['prim minister of India', 'MODI'], ['Any one state name of inida', 'WEST BENGAL'] ]; var Question; var Answer; var HoldCorrect = []; var HoldWrong = [];

function print(message) { var outPutDiv = document.getElementById('demo'); outPutDiv.innerHTML = message; } function PrintAnswer(list) { var tagHTML = '<ol>'; for (var i = 0; i < list.length; i += 1) { tagHTML = '<li>' + list[i] + '</li>'; } tagHTML = '</ol>'; return tagHTML; } for (var i = 0; i < allQuestion.length; i += 1) { Question = allQuestion[i][0]; Answer = allQuestion[i][1]; AskQuestion = prompt(Question); Attemps += 1; if (AskQuestion.toUpperCase() === Answer) { CorrectAnswer += 1; HoldCorrect.push(Question); } else { WrongAnswer += 1; HoldWrong.push(Question); } } PrintAnswer = '<p>Right Answers</p>' + CorrectAnswer + '<br>'; PrintAnswer = ' <p>Wrong Answer</p>' + WrongAnswer + '<br>'; PrintAnswer = ' <H2> This are the question is correct </h2>' + HoldCorrect + '<br>'; PrintAnswer = ' <H2> This are the question is wrong </h2>' + HoldWrong + '<br>'; print(PrintAnswer);

1 Answer

Steven Parker
Steven Parker
231,269 Points

I'm not sure what you mean about "BuildList". I did not see any function by that name in your code.

One thing I did notice in your code is at the end you reassign the variable "PrintAnswer" 4 times before you use it. This means only the last one will be seen. Did you mean to call "print(PrintAnswer);" between the other assingnments?

And when posting code please use the instructions in the Markdown Cheatsheet pop-up link below :arrow_heading_down:. And remember to skip a blank line before the code section.