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 Roberts
Sean Roberts
2,587 Points

Script does not run unless the last "else" statement is an "else if"

Hello everyone, I am running into an issue where the last else statement returns error "Uncaught SyntaxError: Unexpected token {" unless I change it to an else if. Then it run just fine. Any idea why? Thanks everyone.

// quiz begins, no answers correct var correct = 0;

// ask questions var answer1 = prompt("Name a programming language that is also a gem"); if (answer1.toUpperCase() === 'RUBY') { correct += 1; } var answer2 = prompt("Name a programming language taht is also a snake"); if (answer2.toUpperCase() === "PYTHON") { correct += 1; } var answer3 = prompt("What language do you style a webpage in?"); if (answer3.toUpperCase() === "CSS") { correct += 1; } var answer4 = prompt("What language do you use to build the structure of web pages?"); if (answer4.toUpperCase() === 'HTML') { correct += 1; } var answer5 = prompt("What language do you use to add interactivity to a web page?"); if (answer5.toUpperCase() === "JAVASCRIPT") { correct += 1; }

//output results document.write("<p>You got " + correct + " out of five.<p>");

// output rank if (correct === 5) { document.write("<p>Great job you earned a gold crown!!<p>"); } else if (correct >= 3) { document.write("<p> Good job you earned a silver crown!<p>"); } else if (correct >= 1) { document.write("<p> You earned a bronze crown. Keep studying. <p>"); } else (correct === 0) { document.write("<p>No crown for you, best hit those books.<p>"); }

Thats right I have that same problem!

Steven Parker
Steven Parker
231,271 Points

Jorge Vazquez — Didn't removing the conditional expression fix it for you also?

If not, perhaps your cause is different. You may want to start a new question and include your code in it (but please use formatting!)

Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

1 Answer

Steven Parker
Steven Parker
231,271 Points

A plain "else" does not take a conditional expression. It doesn't need one since it handles any condition not already handled by the previous "if" and "else if" blocks.