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

This code won't run!

var score = 0;
var name = prompt("What is your name?");
alert("Hello there " + name + " Lets us play a fun quiz"); 
var answer = prompt("Who is also known as the Imp and is the son of Tywin Lannister" );
if ((answer.toLowerCase() == "tyrion lannister" || answer.toUpperCase() == "TYRION LANNISTER"))
{
  alert( answer + " is the correct answer!");
  score +=1;
}
else()
{
alert("Your answer is  wrong, you are a stupid!");

}
answer = prompt("Who is also a Stark Bastard and serves at the Nights Watch?" );
if ((answer.toLowerCase() == "jon snow" || answer.toUpperCase() == "JON SNOW"))
{
  alert( answer + " is the correct answer!");
  score +=1;
}
else()
{
alert("Your answer is wrong, you are a stupid!");

}

The prompts won't open. Is there some other place to test my JS code apart from the browser's interpreter. This is just rough code, I will simplify things. It just won't run.

5 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Kshitij, you do not need brackets after an else statement as you are not giving it any conditions to follow. On a side note, I noticed you have two conditional statements that amount the same thing, answer.toLowerCase() converts whatever the user enters to lowercase so if they type "TYRION LANNISTER" it will change to "tryion lannister", so really you only need one of these statements, for example:

if (answer.toLowerCase() == "tyrion lannister") //one conditional statement
{
  alert( answer + " is the correct answer!");
  score +=1;
}
else //remove brackets from else
{
alert("Your answer is  wrong, you are a stupid!");

}

Hope that helps!! p.s I love the game of thrones theme :)

Ksjiti,

Your very close on this, just look at the code below and re the "()" from the else clause and you should be good to go.

if you want to test out code you can always go to codepen, i highly recommend it.

http://codepen.io/

var score = 0;
var name = prompt("What is your name?");
alert("Hello there " + name + " Lets us play a fun quiz"); 
var answer = prompt("Who is also known as the Imp and is the son of Tywin Lannister" );
if ((answer.toLowerCase() == "tyrion lannister" || answer.toUpperCase() == "TYRION LANNISTER"))
{
  alert( answer + " is the correct answer!");
  score +=1;
}
else//remove the "()"
{
alert("Your answer is  wrong, you are a stupid!");

}
answer = prompt("Who is also a Stark Bastard and serves at the Nights Watch?" );
if ((answer.toLowerCase() == "jon snow" || answer.toUpperCase() == "JON SNOW"))
{
  alert( answer + " is the correct answer!");
  score +=1;
}
else//remove the "()"
{
alert("Your answer is wrong, you are a stupid!");

}

Grace Kelly and Jacob Mishkin it worked! Thanks! and I tried codepen! Thanks!

Grace Kelly
Grace Kelly
33,990 Points

No problem, glad to help!!

Not a problem. anytime!

Grace Kelly thanks i will try that and run it

Grace Kelly
Grace Kelly
33,990 Points

good luck, and as Jacob has pointed above, you have the issue on two of your else statements so don't forget two remove the brackets twice!!

Jacob Mishkin I will try that.