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

guram dgebuadze
seal-mask
.a{fill-rule:evenodd;}techdegree
guram dgebuadze
Front End Web Development Techdegree Student 4,122 Points

Is my code right to do the same in the future?

var question;
var answer;
var response;
var correct = 'This is the question(s) you got right' + '<ol>';
var wrong = 'This is the question(s) you got wrong' + '<ol>';

function print(message) {
  document.write(message);
}

var questions = [
['When did the \'First world War\' begin? ', 1914],
['When did the \'Second World War\' begin? ', 1939],
['When did the \'Oqtomber Revolution\'  happened in Russia? ', 1917]
];


for (var i = 0; i < questions.length; i++) {
  question =  questions[i][0];
  answer = questions[i][1];
  response = parseInt(prompt(question));

  if ( response === answer ) {
    correct += '<li>' + question + '</li>';
  } else {
    wrong += '<li>' + question + '</li>';
  }
}
correct += '</ol> ';
wrong += '</ol>'; 

print(correct + wrong);
Steven Parker
Steven Parker
231,269 Points

What kind of "future" requirements are you concerned about? I hope not a third world war!

3 Answers

Steven Parker
Steven Parker
231,269 Points

You'll find that the more complex the program, the more ways there will be to write the code to do it. And 90% of "right" is achieving the intended results. The rest is making the code efficient, concise, and easily read and maintained. This code seems to do well in all those criteria, so if it also performs just like the example code, I'd say it's "right" for sure.

Good job! :+1:

Steven Parker
Steven Parker
231,269 Points

Well, good. :wink: But can you elaborate a bit on the question?