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

I can't find the syntax error

var correctAnswers = 0;

var question1 = prompt("Are this the question one? (y/n)");
if (question1 === "y") {
  alert("You're right!");
  correctAnswers += 1;
  alert ("Correct answers : " + correctAnswers );
} else {
  alert("I'm sorry, I hope you have better luck in the next question...");
  alert("Correct answers: " + correctAnswers );
}

var question2 = prompt("Are this the question two? (y/n)");
if (question2 === "y") {
  alert("You're right!");
  correctAnswers += 1;
  alert ("Correct answers : " + correctAnswers );
} else {
  alert("I'm sorry, I hope you have better luck in the next question...");
  alert("Correct answers: " + correctAnswers );
}

var question3 = prompt("Are this the question three? (y/n)");
if (question3 === "y") {
  alert("You're right!");
  correctAnswers += 1;
  alert ("Correct answers : " + correctAnswers );
} else {
  alert("I'm sorry, I hope you have better luck in the next question...");
  alert("Correct answers: " + correctAnswers );
}

var question4 = prompt("Are this the question four? (y/n)");
if (question4 === "y") {
  alert("You're right!");
  correctAnswers += 1;
  alert ("Correct answers : " + correctAnswers );
} else {
  alert("I'm sorry, I hope you have better luck in the next question...");
  alert("Correct answers: " + correctAnswers );
}

var question5 = prompt("Are this the question five? (y/n)");
if (question5 === "y") {
  alert("You're right!");
  correctAnswers += 1;
  alert ("Correct answers : " + correctAnswers );
} else {
  alert("I'm sorry, but it isn't...");
  alert("Correct answers: " + correctAnswers);
}


if (correctAnswers === 5) {
  document.write("<p>You won the gold crown!</p>");
} else if (correctAnswers >= 3) {
  document.write("<p>You won the silver crown!</p>");
} else if (correctAnswers >=1) {
  document.write("<p>You won the bronze crown!</p>");
} else {
  document.write("<p>You could not get any crown, try it again</p>"!);
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Pau,

First off, I added the markdown to make the code readable in the forum. You can see how this was done by going to "edit question" and looking at where and how I added the backticks and language.

As for your syntax error, it is just a typo in your last line of code. Your exclamation mark (!) is outside of the quotation marks. Just move the ! inside the quotes and it works.

document.write("<p>You could not get any crown, try it again</p>!");

Good job, by the way!

Keep Coding! :)

It works! Thank you very much for both helps