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

Aces! With an extra push, from this video I got this code! What do you think?

I got some help from this video, but here's my final result!

I tossed in some else-if statements in the event that all the answers were right or wrong. How's it look?

var quizQs = [
  ["What is the name of the sword Roronoa Zoro inherited from his childhood friend, Kuina?", "wado ichimonji"],
  ["What Mew DNA did Dr. Fuji use to clone Mewtwo?", "eyelash"],
  ["What is the name of Goku's signature move and often mistaken for Hawaiian royalty when pronounced in English?", "kamehameha"],
  ["What is the Endless Vearth Eneru dreams to go to really?", "the moon"],
  ["Which Pokémon stopped the fighting between Articuno, Zapdos and Moltres?", "lugia"],
  ["What does Papyrus enjoy making the most?", "spaghetti"],
  ["What did one of the unused English dubs of One Piece call the meat Luffy eats?", "barbecue"],
  ["What classic game character was not in Wreck-it-Ralph?", "mario"]
];
var score = 0;
var question;
var answer;
var guess;
var response;
var correctCount = [];
var incorrectCount = [];
var html;

function buildList (arr) {
  var listHTML = '<ol>';
  for(var x = 0; x < arr.length; x += 1){
    listHTML += '<li>' + arr[x] + '</li>';
  }
  listHTML += '</ol>';
  return listHTML;
}

for (var x = 0; x < quizQs.length; x += 1 ){
  question = quizQs[x][0];

  answer = quizQs[x][1];

  response = prompt(question);

  guess = response.toLowerCase();
  if (guess === answer){
    score += 1;
    correctCount.push(question);
  } else {
    incorrectCount.push(question);
  }

}

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

if (score === 0) { //flunked
  html = "<p>Sheesh...you got nothin' on that round. Don't give up though! Refresh the page to try again</p>";
} else if (score === 8) { //Aced
  html = "<p>WOW! INCREDIBLE! You aced this!</p>";
} else { //Some right, some wrong.
  html = "<p>You got " + score + " answer(s) right!</p>";
  html += "<p>I know you can get higher though! Refresh the page and try again</p>";
  html += "<h2>Here's What You Got Right</h2>";
  html += buildList(correctCount);
  html += "<h2>Here's What You Got Wrong</h2>"
  html += buildList(incorrectCount);
}

print(html);