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

Curtis Simonson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Curtis Simonson
UX Design Techdegree Graduate 13,791 Points

Javascript: The conditional challenge

What is wrong with my code? Anyone willing to help? //question 1 var questions = 5; var illinois = "Springfield"; var missouri = "Jefferson City"; var colorado = "Denver"; var northcarolina = "Raleigh"; var southcarolina = "Columbia";

var illinois = prompt ("What is the capital of Illinois?"); if (illinois.toUpperCase() == "Springfield") { alert(" You guessed correctly!") } else { alert ("Sorry. Your answer was incorrect.")
} questions -= 1 var questionsleft = (questions + questionsleft);

//questions 2 var missouri = prompt ("What is the capital of missouri?") if (missouri.toUpperCase() == " Jefferson City") { alert ("You guessed correctly!") } else { alert("Sorry. Your answer was incorrect.")
} questions -= 1; var questionsleft = (questions + questionsleft);

//question 3 var colorado = prompt ("What is the capital of colorado?") if (colorado.toUpperCase() == " Denver") { alert ("You guessed correctly!") } else { alert ("Sorry. Your answer was incorrect. ")
} questions -= 1; var questionsleft = (questions + questionsleft);

//question 4 var northcarolina = prompt ("What is the capital of north carolina?") if (northcarolina.toUpperCase() == " Raleigh") { alert (" You guessed correctly! ") } else { alert ("Sorry. Your answer was incorrect. " )
} questions -= 1; var questionsleft = (questions + questionsleft);

//question 5 var southcarolina = prompt ("What is the capital of south carolina?") if (southcarolina.toUpperCase() == " Columbia") { alert (" You guessed correctly! ") } else { alert (" Sorry. Your answer was incorrect." )
} questions -= 1; var questionsleft = ( questions + questionsleft);

alert ("You're done"); alert ("If you answered 5 questions correctly, then you earned a gold crown!"); alert ("If you answered 3-4 questions correctly, then you earned a silver crown!"); alert ("If you answered 1-2 questions correctly, then you earned a bronze crown!"); alert ("If you answered 0 questions correctly, then you did not earn a crown!");

Steven Parker
Steven Parker
231,271 Points

When posting code, always 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.

Also please describe the issue(s) you are having when running the code.

Paul Costanza
Paul Costanza
6,357 Points

In your if statements, you wrote the upper case method, so the string needs to be uppercase. Example: if(illinois.toUpperCase() === "SPRINGFIELD")

1 Answer

Steven Parker
Steven Parker
231,271 Points

I see two issues that would prevent the answers from being considered correct:

  • as Paul mentioned, the case you convert the input to must match the word(s) you compare with
  • most of the answers have a space before the word which the user won't be expecting to enter