Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Jonathan Weinstein
Jonathan Weinstein
9,063 Points

User gets 5 answers correct regardless of input -- anyone know why?

Here's the code:

var correct = 0;
var question1 = prompt('What is the capital of Wyoming?');
if (question1.toUpperCase() ===  "CHEYENNE") {
  correct += 1;
}
var question2 = prompt('What is the capital of Pennsylvania?');
if (question2.toUpperCase() ===  "HARRISBURG") {
  correct += 1;
}
var question3 = prompt('What is the capital of Oregon?');
if (question3.toUpperCase() ===  "SALEM") {
  correct += 1;
}
var question4 = prompt('What is the capital of Kentucky?');
if (question4.toUpperCase() ===  "FRANKFORT") {
  correct += 1;
}
var question5 = prompt('What is the capital of West Virginia?');
if (question5.toUpperCase() ===  "CHARLESTON") {
  correct += 1;
}


if ( correct = 5) {
  document.write('You got ' + correct + ' answers correct! Hooray for useless knowledge!');
    } else if ( correct >= 3 ) {
  document.write('You got ' + correct + ' answers correct! You might be smarter than a 5th grader.');
    } else if ( correct >= 1) {
  document.write('You only got ' + correct + ' answers. Whatever, no one cares about these places anyways.');
    } else {
  document.write('You need to go back to 5th grade.');
    }

1 Answer

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

Jonathan,

It looks like your problem is with this bit:

if ( correct = 5) {

Instead of checking to see if correct equals 5, you're actually setting it to 5. Make sure you use == to check if 2 values are equal.

Hope that helps.

Jonathan Weinstein
Jonathan Weinstein
9,063 Points

Yep, great catch! Thanks a ton :)