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

M Khan
M Khan
7,024 Points

I did exactly like the video but its not showing the total answer

var correct = 0;
var answer1 = prompt("What is the capital of Bangladesh ?");
if (answer1.toUpperCase() === 'Dhaka'){
    correct += 1;
}

var answer2 = prompt("What is the capital of Pakistan ?");
if (answer2.toUpperCase() === 'Islamabad'){
    correct += 1;
}

var answer3 = prompt("What is the capital of England ?");
if (answer3.toUpperCase() === 'London'){
    correct += 1;
}

var answer4 = prompt("What is the capital of Bhutan ?");
if (answer4.toUpperCase() === 'Thimpu'){
    correct += 1;
}

var answer5 = prompt("What is the capital of Australia ?");
if (answer5.toUpperCase() === 'Sydney'){
    correct += 1;
}


document.write("You got " + correct + " out of 5 questions");

if (correct === 5){
    document.write("You got gold medal");
}

else if(correct >=3){
    document.write("You got silver medal");
}
else if(correct >=1){
    document.write("You got Bronze medal");
}
else{
    document.write("You Lost");
}

1 Answer

Ben Reynolds
Ben Reynolds
35,170 Points

You're trying to compare the answer to its all-caps version with the toUpperCase method but none of your if statements check for all-caps strings. For example:

if (answer1.toUpperCase() === 'Dhaka'){

This will always be false. It would need to look like this:

if (answer1.toUpperCase() === 'DHAKA'){