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

Keno Aguiar
Keno Aguiar
4,741 Points

Is what i did any worse than how he did it?

//All of the questions first then their answers var questionsAnswers = [ ['What is my name?', 'keno'], ['How old am I?', 'twenty'], ['Who is my girlfriend?', 'cindy'], ['How old is she?', 'nineteen'], ['What is my brothers name', 'jeremy'], ['How old is he?','seventeen'], ];

//prints to the html page function print(message) { document.write(message); }

//separates correct answers and wrong answers var correctList = '<ol>'; var wrongList = '<ol>';

//loops every question and adds to either correct or wrong for (var i = 0; i < questionsAnswers.length; i += 1){ var question = prompt(questionsAnswers[i][0]); if (question.toLowerCase() === questionsAnswers[i][1]){ correctList += '<li>' + questionsAnswers[i][0] + '</li>'; } else { wrongList += '<li>' + questionsAnswers[i][0] + '</li>'; } }

//end lists correctList += '</ol>'; wrongList += '</ol>';

//prints everything print("Correct Answers"); print(correctList); print("Wrong Answers"); print(wrongList);

Obviously it comes out different, but i just wanted to know if how he does it is a lot more efficient than how i did it.

1 Answer

Steven Parker
Steven Parker
229,657 Points

Your code seems no worse than his. :laughing:

Just kidding, both code examples seem similar in efficiency. Yours keeps track of the specific questions by answer and his only keeps a count, but accounting for that functional difference the basic structure seems equivalent.

Good job. :+1: