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

yousif alyousif
yousif alyousif
2,322 Points

why is only the first part of my code passing ?!

/*this is my code*/ 
var egypt = prompt(" What is the capital of Egypt? ");
var kuwait = prompt(" What is the capital of Kuwait? ");
var thailand = prompt(" What is the capital of Thailand? ");
var turky = prompt(" What is the capital of Turky? ");
var life = prompt(" What is the most defecult game in the world ");
var correct = 0;

/* checking the answers*/
if (egypt.toUpperCase() === cairo) {
  correct += 1;
}
if (kuwait.toUpperCase() === kuwait){
    correct += 1;
}
if (thailand.toUpperCase() === bangkok) { 
  correct += 1;
}
if (turky.toUpperCase() === istanbul) {
  correct += 1;
}
if (life.toUpperCase() === life) {
  correct += 1;
}
/* out put the result */
document.write('<h1> Yo got ' +correct+ ' out of 5 questions correct </h1>');
/* ranking */
if ( correct === 5 ) {
  document.write("<h1><strong> you earned a gold crown! </strong></h1>");
} else if ( correct >= 3) {
  document.write("<h1><strong> you earned a silver crown! </strong></h1>");
} else if ( correct >=1 ) {
  document.write("<h1><strong> you earned a bronze crown! </strong></h1>");
} else {
  document.write("<h1><strong> YOU LOST </strong></h1>");
}
Steven Parker
Steven Parker
231,269 Points

To make your code readable, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down: Or watch this video on code formatting.

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,696 Points

Thanks for pointing @yousif in the right direction. I updated the code formatting in the meantime.

2 Answers

Steven Parker
Steven Parker
231,269 Points

I see two issues here.

  • you forgot to put quotes around your strings (like "cairo")
  • your strings are all lower case, but you convert the input into upper case.
yousif alyousif
yousif alyousif
2,322 Points

thanks for your comment problem been solved

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you are comparing upper-cased strings to lower-cased strings. if you are going to convert the responses to uppercase, you need to compare those responses to uppercase strings to determine if they are correct.