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

CRIS ACOSTA
CRIS ACOSTA
2,121 Points

After 2 days of pulling my hair I finally nailed it! Anyways, a beginner can always use some feedback. Here's my code:

var quiz = [['How many US states are there?', 50], ['What is the best programming language?', 'JAVASCRIPT'], ['Who painted starry starry night?', 'VINCENT VAN GOGH'] ]; var score = 0;

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

function promptQuiz(questions) {

var correctHTML = '<ol>'; var wrongHTML = '<ol>';

for (i=0; i<questions.length; i++){

var answer = prompt(questions[i][0]); if(answer.toUpperCase() == questions[i][1]){
score ++;
correctHTML += '<li>' + questions[i][0] + ': you answered: ' + answer + '</li>'; } else if(answer.toUpperCase() !== questions[i][1]) { wrongHTML += '<li>' + questions[i][0] + ', answer should be: ' + questions[i][1] + '</li>';
} }

correctHTML += '</ol>'; wrongHTML += '</ol>';

document.write('<h4>Score: ' + score + '</h4>'); document.write('<h3>You answered these questions correctly!'); print(correctHTML);

document.write('<h3>Here are the questions you didn\'t get right:</h3>'); print(wrongHTML);

}

promptQuiz(quiz);

I think that's awesome that you stuck with it for two days, and didn't give up! That's how I feel a lot, so it's good to know I'm not the only one!

I believe that is what it takes to be a great programmer. Keep at it till you can figure it out, eventually it will become easier.