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

Zaq Dayton
Zaq Dayton
2,244 Points

When I get 0 questions correct, my score still ends up being 1...

For some reason, I'm not getting the right output when 0 questions are correct in my quiz. All of the others are correct, however. Therefore, if I get 5 right, I get a gold crown. 3-4, I still get a silver. 1-2, I still get a bronze. But, when I get 0 correct, I still get the output for my bronze crown. I can't figure out why though. My code is different than the instructor's, but that shouldn't be an issue from what I can tell. Anybody have any insight as to what might be happening? Thanks in advance!

Here's my code:

// created bc all are assumed as false to begin with
var score = 0;

var ques1 = prompt('How does Mr. Dayton spell his name?');
var ques2 = prompt('How old is Mr. Dayton?');
var ques3 = prompt('Who is Mr. Dayton\'s girlfriend?');
var ques4 = prompt('Who does Mr. Dayton live with?');
var ques5 = prompt('Where does Mr. Dayton live?');

// question 1 answer
if (ques1.toUpperCase() === 'ZAQ') {
 score += 1; 
}

// ques 2 answer
if (parseInt(ques2) === 24) {
  score += 1;
}

// ques 3 answer
if (ques3.toUpperCase() === "AUDREY") {
  score += 1;
}

// ques 4 answer
if (ques4.toUpperCase() === "SPENCER" || ques4.toUpperCase() === "CHARLES") {
  score += 1;
}

// ques 5 answer
if (ques5.toUpperCase() === 'TEXAS'); {
  score += 1;
}

// score notification conditions
if (score === 5) {
  document.write('<p>You know Zaq pretty well. He is giving you his gold crown. Take good care of it.');
} else if (score >= 3) {
  document.write('<p>I suppose you know Zaq a bit more than most, but he still holds the Gold crown. You can have this stupid silver one.');
} else if (score >= 1) {
  document.write('<p>You don\'t know Zaq too well. He deserves the Gold crown. You only get a little bronze one.');
} else if (score === 0) {
  document.write('<p>That\'s right! You will never know the almighty Mr.Dayton!</p>');
}

1 Answer

Steven Parker
Steven Parker
229,732 Points

:point_right: You have a stray semicolon after this IF:

// ques 5 answer
if (ques5.toUpperCase() === 'TEXAS'); {  // <-- note the semicolon on this line
  score += 1;
}

That causes the IF to do nothing if it passes; but then the following block is always performed, adding 1 to the score.

Zaq Dayton
Zaq Dayton
2,244 Points

Haha, of course it would be a semicolon. Needed another pair of eyes on this, thanks for helping out!