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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Dan Spector
Dan Spector
1,979 Points

Unexpected identifier?

The unexpected identifier is on Line 27:

if questionSky.toUpperCase() === 'BLUE'
//five questions

var questionSky = prompt("What color is the sky?");
var questionGrass = prompt("What color is the grass?");
var questionPavement = prompt("What color is the pavement?");
var questionDwarves = prompt("How many dwarves are in Snow White?");
var questionStooges = prompt("How many stooges are there?");

//Keeping track which ones are correct

var QuestionsCorrect = 0;

if questionSky.toUpperCase() === 'BLUE' {  
  var QuestionsCorrect += 1; 
}


if questionGrass.toUpperCase() ===  'GREEN' { 
  var QuestionsCorrect += 1;
}

if questionPavement.toUpperCase() === 'BLACK' {
  var QuestionsCorrect += 1;

}

if parseInt(questionDwarves) === 7 {
  var QuestionsCorrect += 1;

}

if parseInt(questionStooges) === 3 {
    var QuestionsCorrect += 1;
}

//Alerting how many questions are correct

alert("Congrats, you got " + QuestionsCorrect + " questions correct!");

//Bestowing of the crowns

if QuestionsCorrect === 5 {
  document.write("You get a gold crown!"); 
}

else if QuestionsCorrect === 4 || QuestionsCorrect === 3 {
  document.write("You get a silver crown!");

}

else if QuestionsCorrect === 2 || QuestionsCorrect === 1 {
  document.write("You get a bronze crown!");

}

else QuestionsCorrect === 0 {
  document.write("You don't get a crown!");

}

I don't know what is wrong, I've been looking at this for quite a while. Thanks!

Iain Diamond
Iain Diamond
29,379 Points
var questionsCorrect = 0;

if (questionSky.toUpperCase() === 'BLUE') {  
  questionsCorrect += 1; 
}
if (questionGrass.toUpperCase() === 'GREEN') { 
  questionsCorrect += 1;
...
}

Hi Dan, here's a couple of points to note:

  • JavaScript if conditions need to be surrounded with '(' and ')'
  • var questionsCorrect should be declared just once near the top .

Hope this helps.

2 Answers

Vrund Patel
Vrund Patel
11,994 Points

There is a problem with your if statement, basic if statement is as follows:

if (condition) {
   //code 
}

Therefore, your if statements should be changed and also you already made the var QuestionCorrect at the top so there is no need to type var again.

if (questionSky.toUpperCase() === 'BLUE') {  
   QuestionsCorrect += 1; 
}

Hope this helps!

Dan Spector
Dan Spector
1,979 Points

Wow, thanks guys! Some very basic, yet essential things to know!