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
Aaron Endsley
Courses Plus Student 17,625 PointsBuild a Quiz Challenge(Javascript loops, arrays and Objects) Unexpected end of input
I am Currently working the challenge for the 2nd stage of this course and as i was writing my javascript I was checking it in the console for errors and it came up with unexpected end of input on the first line and I can not figure out how to fix it.
var questionAnswer = [
['What is two plus two?', 4],
['What Color is the sky', 'blue'],
['What do you get when you mix red with blue?', 'purple']];
var score=0;
for(var i=0; i<1; i+=1){
var question1=prompt(questionAnswer[0][0]);
if(question1===questionAnswer[0][1]){
score+=1};
var question2=prompt(questionAnswer[1][0]);
if(question2===questionAnswer[1][1]){
score+=1};
var question3=prompt(questionAnswer[2][0]);
if(question3===questionAnswer[2][1]){
score+=1;
}
function print(message) {
document.write(message);
}
if (score===3){
print('congratulations, you got all the questions right.');
}else if(score===2){
print('You got two right, way to go!');
}else if (score===1){
print('You only got one right you need to study up');
}else{
print('You didnt get any right did you even study?');
}
2 Answers
LaVaughn Haynes
12,397 PointsYou have some syntax errors in your for loop.
for( var i = 0; i < 1; i += 1 ){
var question1 = prompt( questionAnswer[0][0] );
if( question1 === questionAnswer[0][1] ){
// wrong: score+=1};
// move semi-colon to other side of curly brace
score += 1;
}
var question2 = prompt( questionAnswer[1][0] );
if( question2 === questionAnswer[1][1] ){
// wrong: score+=1};
// move semi-colon to other side of curly brace
score += 1;
}
var question3 = prompt( questionAnswer[2][0] );
if( question3 === questionAnswer[2][1] ){
score += 1;
}// <- was missing this curly brace
}
Aaron Endsley
Courses Plus Student 17,625 Pointsthank you thank you, guess i just need to look more closely on my syntax
LaVaughn Haynes
12,397 PointsHa! It happens to us all