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

2nd question prompt not showing up. What's wrong with my code?

Hi guys, I've taken the advice of the instructor and I'm running my code little by little. The first time I ran this code it was fine, the problem is begins with the second question. When I put the second question in the quiz the program failed to run at all. The Dev Tools mentioned a syntax error on line 21 but as much as I've looked I can't seem to find it. Can you let me know what you think the problem is?


Quiz.js:

var guessedRight = 0; //Beginning of the questions var quest1 = prompt("What's the best programming language?");

if(quest1 === "javascript") {

document.write("Absolutely");
guessedRight+= 1;

} else { document.write("I'm sorry, wrong answer"); }

var quest2 = prompt("What's the hardest part of programming");

if(quest2 === "logic") {

document.write("You got it");
guessedRight+= 1; } else { document.write("logic is definitely the hardest thing to master.");

2 Answers

Dan Weru
Dan Weru
47,649 Points

Hey you had a slight syntax error at line 21. You left out the closing curly brace to close the second else statement. This should work ... compare the last line with your code.

var guessedRight = 0; 

//Beginning of the questions

var quest1 = prompt("What's the best programming language?");

if (quest1 === "javascript") {
  document.write("Absolutely");
  guessedRight+= 1;
} else { 
  document.write("I'm sorry, wrong answer"); 
}

var quest2 = prompt("What's the hardest part of programming");

if (quest2 === "logic") {
  document.write("You got it");
  guessedRight+= 1; 
} else {
   document.write("logic is definitely the hardest thing to master.");
}

Thanks for that. Its been adjusted.