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 trialJake Ford
9,230 PointsThe way I did the Quiz
Just wanted to share how I did it for any feedback. I realize it is not as readable as the way Dave did. Anyone else do it like this?
var qna = [
['What is Jake\'s favorite color?', 'green'],
['What is Justin\'s favorite color?', 'blue'],
['What is Mom\'s favorite color?', 'green'],
['What is Dad\'s favorite color?', 'purple']
];
var correct = 0;
var guess;
for( var i = 0; i < qna.length; i++ ){
guess = prompt( qna[i][0] );
guess = guess.toLowerCase();
if( guess === qna[i][1] ){
correct++;
}
}
document.write('You have guessed ' + correct + ' questions correctly out of 4 total.');
1 Answer
Thomas Nilsen
14,957 PointsI think this line
guess = prompt( qna[i][0] );
guess = guess.toLowerCase();
Is kind of unnecessary. Just write it like this:
guess = prompt( qna[i][0] ).toLowerCase();
Jake Ford
9,230 PointsJake Ford
9,230 PointsYou're right! Thanks!