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

I've been getting 4 answers correct instead of 5

/*

  1. Create a quiz that asks 5 questions.

  2. Keep track of the number of questions the answer used correctly.

  3. Provide a final message after the quiz letting the user know the number of questions he or she got right.

  4. Rank the player. Five questions answered correctly is a gold crown, three to four questions answered correctly is a silver crown, one to two questions answered correctly is a bronze crown, and zero questions answered correctly is no crown at all. */

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

//Get user input, make give requirements to answer questions //Used \n to get a line break between question and requirement var question1 = prompt("What are the primary colors? \nPlease enter the correct numbers like so ex. 2,3,4 given that \n1) Red \n2) Orange \n3) Yellow \n4) Green \n5) Blue \n6) Purple "); if (question1 === "1,3,5"){ correct += 1; } var question2 = prompt("What are the primary colors that make up green? \nPlease enter the correct numbers like so ex. 2,3 given that \n1) Red \n2) Yellow \n3) Blue"); if (question2 === "2,3"){ correct += 1; }

var question3 = prompt("What are the primary colors that make up purple? \nPlease enter the correct numbers like so ex. 2,3 given that \n1) Red \n2) Yellow \n3) Blue "); if (question3 === "1,3"){ correct += 1; }

var question4 = prompt("What are the primary colors that make up orange? \nPlease enter the correct numbers like so ex. 2,3 given that \n1) Red \n2) Yellow \n3) Blue"); if (question4 === "1,2"){ correct += 1; }

var question5 = prompt("What is the one color when all of the colors are combined?"); if (question5.toUpperCase === "WHITE"){ correct += 1; }

//output the results document.write("You got " + correct + " right! ");

//output rank if (correct === 5){ document.write("You earned a gold crown!"); }else if(correct >= 3){ document.write("You earned a silver crown!"); }else if(correct >= 1){ document.write("You earned a bronze crown!"); }else { document.write("Zero correct, no crown for you."); }

1 Answer

Steven Parker
Steven Parker
231,007 Points

To invoke ("call") a method or function, the name must be followed by parentheses whether or not one or more arguments are being passed:

if (question5.toUpperCase === "WHITE") {    // so this line...
if (question5.toUpperCase() === "WHITE") {  // ...should look like this
Julio Gonzalez
Julio Gonzalez
3,059 Points

Thanks for this! One small thing I overlooked on 4 out of the 5 answers.