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
Michael Smith
8,222 PointsJavascript Syntax error
I am trying to add an else statement to this code, but it is giving me an syntax error that I can't find.
// quiz begins, no answers correct
var correct = 0;
// ask questions
var answer1 = prompt('Name a language that rhymes with ooby');
if (answer1.toUpperCase() === 'RUBY'); {
correct += 1;
}
console.log(correct);
var answer2 = prompt('Name a language that is also a snake.');
if (answer2.toUpperCase() === 'PYTHON'); {
correct += 1;
} else {
correct -= 1;
}
console.log(correct);
var answer3 = prompt('What language do we use to style web pages?');
if (answer3.toUpperCase() === 'CSS'); {
correct += 1;
}
console.log(correct);
var answer4 = prompt('What language do we use to structure our web pages?');
if (answer4.toUpperCase() === 'HTML'); {
correct += 1;
}
console.log(correct);
var answer5 = prompt('What language do you use to add interactivity?');
if (answer5.toUpperCase() === 'JAVASCRIPT'); {
correct += 1;
}
console.log(correct);
// output results
document.write('<p>You got <strong>' + correct + '</strong> out of <strong>5</strong> questions correct</p>');
// outpuk rank
if ( correct === 5) {
document.write('<p><strong>You earned a gold crown!</strong></p>');
} else if ( correct >= 3 ) {
document.write('<p><strong>You earned a silver crown!</strong><p>');
} else if ( correct >= 1 ) {
document.write('<p><strong>You earned a bronze crown!</strong><p>');
}
1 Answer
Mladen Ignjatovic
13,602 PointsHi Michael,
You don't need semicolons after parenthesis in if statement . Try to remove them then try again.You have it in all your statements.
Jason Anello
Courses Plus Student 94,610 Pointschanged from comment to answer
Michael Smith
8,222 PointsMichael Smith
8,222 PointsAwesome it works now, and I don't have decrement the 'correct' variable.
Thanks Mladen!
+1