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

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 :)