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
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 PointsMy solution to Build a Quiz challenge part 2
var quiz = [
[1, 'Who is the president of the USA?', 'donald trump'],
[2, 'What country lies in the north of Germany?', 'denmark'],
[3, 'Who translated the bible into German?', 'martin luther']
];
var html;
var correctAnswer = '<h2>correct answer(s):</h2>' + [];
var wrongAnswer = '<h2>wrong answer(s):</h2>' + [];
var question;
var answer;
var correct = 0;
for ( var i = 0; i < quiz.length; i++ ) {
answer = quiz[i][2];
question = prompt( quiz[i][1] );
if ( question.toLowerCase() === answer ) {
correct += 1;
correctAnswer += '<ol>' + [quiz[i][1]] + '</ol>';
} else {
wrongAnswer += '<ol>' + [quiz[i][1]] + '</ol>';
}
}
function print(message) {
document.write(message);
return message;
}
html = '<p>you have ' + correct + ' correct answers.</p>';
print(html);
print(correctAnswer);
print(wrongAnswer);
1 Answer
Piotr Manczak
Front End Web Development Techdegree Graduate 29,609 PointsI think you did not have to use 'return' command in print function. Except for that it's pretty efficient. Well done!