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

Alexandra Wakefield
Alexandra Wakefield
1,866 Points

My Solution! What Do You Think?

var questions = [
  ["What is the name of the first of the three thoracic segments of an insect?",
  "prothorax"],
  ["What is the name of tongue-like structure that molluscs use to scrape up food?",
  "radula"],
  ["What is the fibrous protein that makes up many sponge frameworks?",
  "spongin"],
  ["What is the pincher-like appendage that some crustaceans and arachnids have?",
  "chela"],
  ["What is the name of the beak of a bivalve?",
  "umbo"]
];

var rightAnswer = "";
var wrongAnswer = "";

//Asking the questions from above and recording if their answers are coreect or not.

for(j = 0; j < questions.length; j++) {
  var answer = prompt(questions[j][0]);
  var questionNum = j + 1;
  if(answer.toLowerCase() === questions[j][1]) {
    rightAnswer += "<ol>" + questionNum + ".) " + questions[j][0] +
    "<ul>Your Answer = " + answer + "</ul>" + "</ol>";
  } else {
    wrongAnswer += "<ol>" + questionNum + ".) " + questions[j][0] +
    "<ul>Your Answer = " + answer + "</ul>" +
    "<ul>Correct Answer = " + questions[j][1] + "</ul>" + "</ol>";
  }
}

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

printAnswers("<h2><b>Questions Answered Correctly</b></h2>" + "<list>" + rightAnswer + "</list>");
printAnswers("<h2><b>Questions Answered Incorrectly</b></h2>" + "<list>" + wrongAnswer + "</list>");

1 Answer

Steven Parker
Steven Parker
229,644 Points

I think you got it, mostly. :smile:

Functional, concise, and readable. Good job! :+1:

You only have some minor HTML structure/syntax issues:

  • the direct child elements of lists (either ol or ul) should all be list items (li).
  • I don't think "<list>" is a real HTML tag.

It doesn't look like you really need lists here, just a bit of indentation. You could use <blockquote> tags or a bit of CSS styling to get the effect you want.

Alexandra Wakefield
Alexandra Wakefield
1,866 Points

Thank you!

Haha, you're totally right, <list> is definitely not an HTML tag, but [list] is a BBCode one and I think I accidentally mixed the two.