Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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);

Butler Fuqua
Butler Fuqua
5,643 Points

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.