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

The answers to my questions continually come back as incorrect, any ideas why?

The only question that works is usCity, I'm not sure what I'm missing. thanks, if you can figure this out

console.log("start program");
var Answer= false;
var correct= 0;
var questions= 5;
var questionsLeft=  "(There are " + questions + "questions left)";

// questions
var japFlag= prompt("What color is the cirlce on japanese flag");
if (japFlag.toUpperCase=== "red") {alert("correct");
                                     correct+= 1;}
else {alert("incorrect");}

questions-= 1;
questionsLeft="(There are " + questions + "questions left)";


var usFlag= prompt("what color is the stars on  the U.S. flag?");
if (usFlag.toUpperCase=== "white"){alert("correct");
                                    correct+= 1; }
else{alert("incorrect");}

questions-= 1;
questionsLeft= "(There are " + questions + "questions left)";


var japCity= prompt("What is japan's largest city?");
if (japCity.toUpperCase=== "tokyo") {alert("correct");
                                      correct+= 1;}
else {alert("incorrect");}

questions-= 1
questionLeft= "(There are " +questions + "questions left)";


var usCity= prompt("What is largest in the U.S.?");
if (usCity.toUpperCase=== "los angeles"||usCity==="la") {alert("correct");
                                                           correct+= 1;}
else {alert("incorrect");} 

questions-= 1;
questionsLeft="(There are " + questions + "questions left)";


var largeState= prompt("What is the largest state in the U.S.?");
if (largeState.toUpperCase==="alaska") {alert("correct");
                                          correct+= 1;}
else {alert("incorrect");}

questions-= 1;
questionsLeft="(There are " + questions + "questions left)";

//output results
alert("You got "+ correct + " out of 5 questions");


if( correct===5) {alert("you earned a gold crown");}
else if(correct >= 3) {alert("you earned a silver crown");}
else if(correct >= 1) {alert("you earned a bronze crown");}
else {alert("you didn't earn a crown");}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,863 Points

Hey Brandon,

I think it's because you are using .toUpperCase, but you are strictly comparing to a lower case string (your answer). Either change your answers to all upper case or change your method to .toLowerCase. Personally, I would change the method.

Hope that fixes it. Keep Coding! :)

Note: I also changed your mark down to read easier. You had it almost right... 3 back ticks+programming language and then after all the code on a new line 3 more back ticks.