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

Sean Flanagan
Sean Flanagan
33,235 Points

Why won't my code run?

Hi.

My code won't execute.

Here's a snapshot of my workspace.

https://w.trhou.se/8ub4wei7sf

Thanks in advance.

Sean

5 Answers

Hello again

Try this

question5.toUpperCase() === "PYTHON"

Instead of this

question5.toUpperCase() === "Python"

You made the same mistake with the ruby question, but the html and css were in uppercase thats why they worked.

If you are converting an answer to uppercase. The answer that it matches must be uppercase aswell.

Hope i'm clear, I suck at explaining things lol.

Paul

Hey Sean

You have a slight syntax error with regards to your concatenation.

if (numOfRightAnswers === 5) {
  document.write("Congratulations on getting " + numOfRightAnswers + " right. | Gold Crown!");
} else if (numOfRightAnswers === 4 || numOfRightAnswers === 3) {
  document.write("Congratulations on getting " + numOfRightAnswers  + " right. | Silver Crown!");
} else if (numOfRightAnswers === 2 || numOfRightAnswers === 1) {
  document.write("Congratulations on getting " + numOfRightAnswers + " right. | Bronze Crown!");
} else {
  document.write("Sorry, you got " + numOfRightAnswers + " right. No crown for you.");
}

You missed the + in between numOfRightAnswers and the rest of your text.

Hope this helps. Let me know if you need any more help

Happy coding

Paul

Just to add....Your first port of call for errors in JS is usually the console in your browser. Any syntax errors etc get thrown straight away.

Cheers Paul

Steven Parker
Steven Parker
231,007 Points

You're doing some string concatenation on lines 61, 63 and 65, but in each case, there's a missing operator ("+") between "numOfRightAnswers" and the string that follows it.

Also, I noticed you are upper-casing your literal strings and not the user input, so a question is only counted right if the user enters it in all upper case. If you wanted to make the answer case-insensitive, you could uppercase the input instead and just have the answers stored in upper case:

if (question1 === "html".toUpperCase() ||   // so instead of this
if (question1.toUpperCase() === "HTML" ||   // you might do THIS
Sean Flanagan
Sean Flanagan
33,235 Points

Hi Paul, Steven. Thanks for your help.

I've edited the code but it still doesn't work right. The last two questions I answer right and it tells me I'm wrong.

New snapshot:

https://w.trhou.se/56ffzpbvsi

Sean

Steven Parker
Steven Parker
231,007 Points

You still need to make the changes I mentioned regarding storing the answers in upper case. Converting the input to upper case but then matching it against mixed-case strings will always fail.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi guys. That worked a treat.

Thank you both.

Sean :-)