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

Viraj Joshi
Viraj Joshi
2,815 Points

Is my code acceptable

var answerCorrect=0;
var correct=[];
var wrong=[];
var playList = [
    [ 'What is my name   ','Viraj'],
    ['What is the first element   ','Hydrogen'],
    ['What grade am I going to   ', 'tenth']

];

function print(message) {
  document.write(message);
}
var answer=prompt(playList[0][0]);
var answer1=prompt(playList[1][0]);
var answer2=prompt(playList[2][0]);
function printList( list ) {
  var listHTML = '<ol>';

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

        if(answer ===list[i][1]){
            correct.push(answer);
        }
       else {
            wrong.push(answer)
      }
      if(answer1 ===list[i][1]){
            correct.push(answer1);
        }
       else {
            wrong.push(answer1)
      }
      if(answer2 ===list[i][1]){
            correct.push(answer2);
        }
        else {
            wrong.push(answer2)
      }


  }
      print("You got"+correct.length+ " correct!!");

    for(var i=0;i<1;i++){
        listHTML+="<strong>"+"What you put"+"</strong>"
      listHTML += '<li>' + list[i][0]+ answer + '</li>';
      listHTML += '<li>' + list[i][0]+ answer1 + '</li>';
      listHTML += '<li>' + list[i][0]+ answer2 + '</li>';
    }


  listHTML += '</ol>';
  print(listHTML);
}



printList(playList);

Hey Viraj, a quick tip. It's very hard to read through your question. To format your code so we can read it properly follow this forum post by Dave McFarland. It shows you how to format each language for forum readability.

https://teamtreehouse.com/forum/posting-code-to-the-forum

Happy coding! :)