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

Prompt not showing when using the IF statement

Hi,

The first part of my code works until i get to the if statement after the document.write command. Code works and shows how many questions answered correctly but when I use the IF statement the prompt stops showing. Here is the code:

Here is my code. The first part works adding the score but when I add in the if statement at the end it stops bringing up prompt and asks no questions:

var correct = 0;

var answer1 = prompt("Whats the capital of Ireland"); if (answer1.toUpperCase() === "DUBLIN"){ correct += 1; }

var answer2 = prompt("Whats the capital of America"); if (answer2.toUpperCase() === "NEW YORK"){ correct += 1; }

var answer3 = prompt("Whats the capital of England"); if (answer3.toUpperCase() === "LONDON"){ correct += 1; }

var answer4 = prompt("Whats the capital of France"); if (answer4.toUpperCase() === "PARIS"){ correct += 1; }

var answer5 = prompt("Whats the capital of Wales"); if (answer5.toUpperCase() === "CARDIFF"){ correct += 1; }

document.write("<p>You guessed " + correct + " questions correctly.</p>");

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 silver crown!</strong></p>");

} else if (correct >== 1){ document.write("<p><strong>You earned a bronze badge!</strong></p>");

} else { document.write("<p><strong>You never earned any badges</strong></p>"); }

2 Answers

Sam Baines
Sam Baines
4,315 Points

Hi Noel - not sure if this is the reason it is not working but in your if statement your operators look odd - I dont think it needs to be (correct >== 3) it rather needs to be (correct >= 3) - I think adding the extra = equal sign is causing an issue. also remember to use your javascript console to see where the error is aka on which line in your code. Hope this helps.

Hi Sam,

Your right only needed one = operator after > symbol.

Also, used the console and discovered double closing brackets at the end of the if statement before the else if statement. Amended, checked, success!

Thanks Sam

Sam Baines
Sam Baines
4,315 Points

Glad I could help - I general have a rule that when ever something doesnt run to check the js console and then my code first, 9 times out of 10 it solves your problem.

Thanks Sam, thats a process I will follow from now on.