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!
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

akash dikkaram
1,927 PointsQuiz Challenge, Part 2 - JavaScript Loops, Arrays and Objects I having It Wrong In the List!!
<html> <head></head> <body>
<h2>Javascript Quiz</h2>
<script>
var correct=[];
var wrong=[];
var html;
function list(array){
var listhtml='<ol>';
for(i=0;i<array.length;i++)
{
listhtml+='<li>'+array[i]+'</li>';
}
listhtml+='</ol>'
return listhtml;
}
var qanda=[['States','29'],
['tamilnadu','chennai'],
['india','delhi']
];
for(i=0;i<qanda.length;i++)
{
var response =prompt(qanda[i][0]);
if(response===qanda[i][1])
{
correct+=qanda[i][0];
}
else
{
wrong+=qanda[i][0];
}
}
document.write('<h3>Thse are correctly answered</h3>')
document.write('<p>'+list(correct)+'</p>')
document.write('<h3>Thse are wrongly answered</h3>')
document.write('<p>'+list(wrong)+'</p>')
</script>
</body>
</html>
1 Answer

Iain Simmons
Treehouse Moderator 32,303 PointsTo add an item to an array, pass it as an argument to the push
method:
correct.push(qanda[i][0]);
akash dikkaram
1,927 Pointsakash dikkaram
1,927 Pointsthanks lain
Iain Simmons
Treehouse Moderator 32,303 PointsIain Simmons
Treehouse Moderator 32,303 PointsThis is because you can only add (
+=
) to variables that are of a certain type (numbers, strings, etc).