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

Ben Ahlander
Ben Ahlander
7,528 Points

SyntaxError on line 15?

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

var questions = [ ["Who is Bens favorite CEO?","ELON MUSK"], ["Why is 6 afraid of 7?","7 ate 9"], ["Is Ben smart?","YES"], ];

var rightAnswer = ""; var wrongAnswer = "";

for (var i=0, i<questions.length, i+=1) { var answer = prompt[i][0]); var questionNum = i + 1;

if(answer[0].toUpperCase === questions[i][1]) { "<h2>"rightAnswer += questionNum + questions[j][0] + "Your Answer = " + answer ". Great Job! </h2>"; } else { wrongAnswer += questionNum + questions[j][0] + "Your Answer = " + answer + "Correct Answer = " + questions[j][1]; } }

printAnswers("<h2><b>Questions Answered Correctly</b></h2>" + " rightAnswer ); printAnswers("<h2><b>Questions Answered Incorrectly</b></h2>" + wrongAnswer);

3 Answers

Steven Parker
Steven Parker
229,771 Points

You have the wrong punctuation.

In the for statement, you separated the clauses with commas, but they should be separated with semicolons.

And for the line numbers to be useful in your code, you must format it using the instructions in the Markdown Cheatsheet found below the "Add an Answer" area. :arrow_heading_down:

Ben Ahlander
Ben Ahlander
7,528 Points

Thanks Steven! Now there is this error "Uncaught SyntaxError: Unexpected identifier" within my if else statement.

Ben Ahlander
Ben Ahlander
7,528 Points

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

var questions = [ ["Who is Bens favorite CEO?","ELON MUSK"], ["Why is 6 afraid of 7?","7 ate 9"], ["Is Ben smart?","YES"], ];

var rightAnswer = ""; var wrongAnswer = "";

for (var i=0; i<questions.length; i+=1) { var answer = prompt[i][0]; var questionNum = i + 1;

if(answer[0].toUpperCase === questions[i][1]) { "<h2>" rightAnswer += questionNum + questions[i][0] + "Your Answer = " + answer ". Great Job! </h2>"; } else { wrongAnswer += questionNum + questions[i][0] + "Your Answer = " + answer + "Correct Answer = " + questions[j][1]; } }

printAnswers("<h2><b>Questions Answered Correctly</b></h2>" + " rightAnswer ); printAnswers("<h2><b>Questions Answered Incorrectly</b></h2>" + wrongAnswer);

Steven Parker
Steven Parker
229,771 Points

When you combine strings, make sure you have the concatenation operator ("+") between each item being combined. Also make sure you only combine strings on the right side of an assignment.