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 trialDan Spector
1,979 PointsUnexpected 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!
2 Answers
Vrund Patel
11,994 PointsThere 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
1,979 PointsWow, thanks guys! Some very basic, yet essential things to know!
Iain Diamond
29,379 PointsIain Diamond
29,379 PointsHi Dan, here's a couple of points to note:
Hope this helps.