Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Code not working

https://w.trhou.se/5x6exdgdc1 ... This is a snapshot of my workspace

I don't see why it doesn't work like how i want it to. After the first question it stops executing. What can i do to fix this? Or just improve my code in general in this workspace.

1 Answer

Cameron Childres
MOD
Cameron Childres
Treehouse Moderator 11,720 Points

Hi Haki,

Take a close look inside the conditional statement of your first question. A single equals sign is the assignment operator so the code is attempting to assign answerOne to firstQuestion.toUpperCase(). If you check your console you'll see this error:

Uncaught ReferenceError: Invalid left-hand side in assignment at quiz.js:34

This is only failing because you can't assign a value to firstQuestion.toUpperCase(). If the toUpperCase() wasn't present here the assignment would succeed and return the string "albany", and since strings are considered truthy the statement would always run -- increasing the correct score by 1 even if the answer itself was incorrect. Be sure to use comparison operators like == or === when comparing values.

One more thing to note about your comparisons. All of your answers are stored as lower cased strings, but you're converting the user's answer to upper case before the comparison:

const answerTwo = "austin";

let secondQuestion = prompt("What is the capital of texas?");
if ( secondQuestion.toUpperCase() === answerTwo  ) {
  correct += 1;
}

If I input "austin" it will be converted to "AUSTIN" before being checked against "austin". This makes it impossible to receive a correct answer. To solve this you can either use the .toLowerCase() method instead or store your answers in uppercase.

I hope this helps! Let me know if you have any questions :)