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

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1

Uncaught SyntaxError: Unexpected end of input quiz.js: 22

I seem to be getting an error message in the console can someone please advise as I think my code is correct.

https://teamtreehouse.com/workspaces/41486415

Thanks

Steven Parker
Steven Parker
231,275 Points

You can't share a direct URL to your workspace, it's temporary and only exists while you are using it.
But you can use the snapshot function in the workspace and provide the link to that.

2 Answers

Hi Steven,

function print(message) {
  document.write(message);
}

let correct;
let questions = [
  ['what is my wife name?', 'Mary'],
  ['what is my mums name?', 'Jane'],
  ['what is my dads name?', 'John'],
  ['what is my brothers name?', 'Chris']
];


  for (let i=0; i< questions.length; i+=1) {
    let userAnswer = prompt (questions [i][0])
    if(userAnswer === questions [i][1]) {
    correct ++;
    };

   print (`You answered ${correct} out of ${questions.length} right.`);
Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,708 Points

Question updated with code formatting. Check out the Markdown Cheatsheet below the Add an Answer submission for syntax examples, or choose Edit Question from the three dots next to Add Comment to see how I improved the readability.

Steven Parker
Steven Parker
231,275 Points

The snapshot is a much better way to make your issue easy to replicate. If you must post code, use use Markdown formatting to preserve the appearance,

But it looks like you forgot to give "correct" an initial value (0), and the "for" loop seems to be missing a closing brace.