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 trialRonnelle Torres
5,958 PointsFeedback please - This is how I did the challenge (28 lines).
function print(message) {
document.write(message);
}
var questions_Answers = [
[prompt('How many states are in the united states?'), 50],
[prompt('What is the color of the sky?'), 'blue'],
[prompt("What's the color of apple?"), 'red']
];
var counter=0;
function printResult (questions) {
var correctAnswers='<h2>Questions that you got correct</h2><ol>';
var wrongAnswers='<h2>Questions that you got wrong</h2><ol>';
for (var i=0; i < questions.length; i+=1) {
if (questions[i][0]===questions[i][1]) {
correctAnswers+= '<li> You got question number ' + [i] + ' correct! The answer is '+ questions[i][1] + '</li>';
counter +=1;
} else {
wrongAnswers+='<li> You got question number ' + [i] + ' wrong. The answer is '+ questions[i][1] + '</li>';
}
}
correctAnswers+='</ol>';
wrongAnswers+='</ol>';
print('<p>You got a total of ' + counter + ' correct answer/s out of ' + questions.length +
' questions.</p>');
print(correctAnswers);
print(wrongAnswers);
}
printResult(questions_Answers); ```
2 Answers
Alexander Davison
65,469 PointsWOW That website was amazingly great! 3x Better than I thought it will
jai kathuria
Courses Plus Student 1,335 PointsAccording to me these are the slight changes that must be made to your program.
function print(message) {
document.write(message);
}
var questions_Answers = [
[prompt('How many states are in the united states?'), '50'],
[prompt('What is the color of the sky?'), 'blue'],
[prompt("What's the color of apple?"), 'red']
];
var counter=0;
function printResult (questions) {
var correctAnswers='<h2>Questions that you got correct</h2><ol>';
var wrongAnswers='<h2>Questions that you got wrong</h2><ol>';
for (var i=0; i < questions.length; i+=1) {
if (questions[i][0]===questions[i][1]) {
correctAnswers+= '<li> You got question number ' + [i+1] + ' correct! The answer is '+ questions[i][1] + '</li>';
counter +=1;
} else {
wrongAnswers+='<li> You got question number ' + [i+1] + ' wrong. The answer is '+ questions[i][1] + '</li>';
}
}
correctAnswers+='</ol>';
wrongAnswers+='</ol>';
print('<p>You got a total of ' + counter + ' correct answer/s out of ' + questions.length +
' questions.</p>');
print(correctAnswers);
print(wrongAnswers);
}
printResult(questions_Answers);