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

Need help with quiz.js please

var correct = 0;

var answer1 = prompt("What number is between five and seven?"); if ( answer1.toUpperCase() === "SIX" ) { correct += 1; } var answer2 = prompt("who is the president now?"); if (answer2.toUpperCase() === "TRUMP" ){ correct += 1; } var answer3 = prompt("how do birds fly?"); if (answer3.toUpperCase() === "WINGS" ){ correct =+ 1; } var answer4 = prompt("What is the name of the capital of New York State?"); if (answer4.toUpperCase() === "ALBANY" ){ correct += 1; } var answer5 = prompt("What is the fastest animal alive"); if (answer5.toUpperCase() === "CHEETAH" ){ correct += 1; }

//output results

document.write("<p>You got " + correct + " out of 5 question correct.<p>");

           //rank output

if( correct === 5 ){ document.write("<p><strong>You earned a Gold crown</strong></p>"); } else if ( correct >= 3 ) { document.write("<p><strong>You earned a sliver crown</strong></p>"); } else if ( correct >= 1 ) { document.write("<p><strong>You earned a sliver crown</strong></p>"); } else { document.write("<p><strong>Nothing For You</strong></p>"); }

5 Answers

Steven Parker
Steven Parker
243,656 Points

You also have a typo.

Once you un-scramble the source, you also have a typo on this line in the third question section:

    correct =+ 1;

I'm sure you meant to put "correct += 1;" like you have in the other sections.

Thank you Steven Parker you solved my problem. It was a typo in the code.

Hi Chris,

So that more experienced developers can assist you, write your Community posts with a clear question and explanation of why you are not getting the intended result that you want. For example, your code above might be throwing an error or just giving the wrong feedback based on the logic in the program - try to explain what's happening vs. what you're expecting to happen.

Also, can you please put your question in a more readable format? Put any code into a code block (start it with 3 backticks ` and end it with 3 more)? I'd be happy to help once I understand the problems that you're running into.

Thanks, Stephen

Steven Parker
Steven Parker
243,656 Points

:point_right: It looks like this code may have been scrambled during editing.

I see what appears to be bits of code that are repeated, and not on even line boundaries. This is causing run-on strings, multiply defined variables, and other issues.

I'm guessing either there was a problem copying the code to this page, or perhaps the code was actually in this form as a result of some editing mishap.

It's not giving me correct answer.

It made to many copies sorry about that.