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

Yogita Verma
Yogita Verma
5,549 Points

My code is not working it is always giving "You got Gold!!" as an answer.

document.write("Quizz");
var rightans=0;
var ans1=prompt("Who is Yogita?");
if(ans1=="S");
  rightans++;
var ans2=prompt("Who is Shakuntala?");
if(ans2=="M");
  rightans++;
var ans3=prompt("Who is Omprakash?");
if(ans3=="F");
  rightans++;
var ans4=prompt("Who is Tarun?");
if(ans4=="B");
  rightans++;
var ans5=prompt("Who is Yamini?");
if(ans5=="S");
  rightans++;
if(rightans===5)
  document.write("\nYou got Gold!!");
 else if(rightans===4 ||rightans===3)
  document.write("\nYou got Silver!!");
 else if(rightans===2 ||rightans===1)
  document.write("\nYou got Bronze!!");
else
  document.write("\nYou got Nothing!!");
Michael Pashkov
Michael Pashkov
22,024 Points

Hi! Where is your '{' ? It should look like 'if () {;} else if () {;} else {;}'

3 Answers

Steven Parker
Steven Parker
229,771 Points

An "if" statement only controls a single statement or code block that immediately follows it. A semicolon after an "if" represents an empty statement, making the entire conditional a no-op.

For future questions, consider making a snapshot of your workspace and posting the link to it here. Or follow Alexander's advice about formatting. This video on code formatting may be helpful.

Yogita Verma
Yogita Verma
5,549 Points

Thanks a lot !! It worked .

Alexander Solberg
Alexander Solberg
14,350 Points

Check the "Markdown Cheatsheet" for instructions on how to format code in your post. It makes it much much easier to figure out what is going on. It should be right below the textarea where we write answers, comments etc.

Alexander Solberg
Alexander Solberg
14,350 Points

From what I can figure out though, it seems like you are forgetting to put curly-braces after your conditionals, so they aren't really doing anything. Try to do something like this

if (ans1 == "S") {
  rightans++;
}