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

Inelegant solution

Javascript loops, arrays and objects Quiz Challenge

Here is my solution to Quiz challenge.

var qanda = [
["What is the capital of Illinois?", "springfield"],
["What is the last name of the governor of Illinois?", "rauner"],
["What is the Illinois State Bird", "cardinal"]
];
var rightAnswers = '';
var wrongAnswers = '';
var right = 0
var wrong = 0
function quiz() { 
for (var i = 0; i < qanda.length; i++) {
  var answer = prompt(qanda[i][0]);

  if (answer.toLowerCase() !== qanda[i][1]) {
  wrongAnswers += "<p>You got answer " +[i + 1]+ " wrong. The correct answer is " +qanda[i][1] + ".</p>";
    wrong += 1;
  } else {
    rightAnswers += "<p>You got answer " + [i + 1]+ " right! The correct answer is " +qanda[i][1] + ".</p>";
  right += 1;
  }

}
 print("<h2>You got " +right+ " answers right.</h2>" + rightAnswers);
 print("<h2>You got " +wrong+ " answers wrong.</h2>" + wrongAnswers);
}
function print(message) {
  document.write(message);
}

quiz();

This works but seems it could be improved on.