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 trialJorge Santander
2,282 Pointsi get an error message on the console of "Uncaught SyntaxError: Invalid destructuring assignment target". why?
var questions = {question: 'How many states are in the United States?',answer: 50},
{question:'How many continents are there?',answer: 7},
{question:'How many legs does an insect have?',answer: 6};
var correctAnswers = 0; var question; var answer; var response;
function print(message) { document.write(message); }
for (var i = 0; i < questions.length; i += 1) { question = questions[i].question; answer = questions[i].answer; response = prompt(question); response = parseInt(response); if (response === answer) { correctAnswers += 1; } }
html = "You got " + correctAnswers + " question(s) right." print(html);
1 Answer
anthony amaro
8,686 Pointshello jorge i see that you are trying to loop on an object. to fix you problem just wrap all your questions in brackets
var questions = [
{question: 'How many states are in the United States?',answer: 50},
{question:'How many continents are there?',answer: 7},
{question:'How many legs does an insect have?',answer: 6}
];
i hope this helps