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

Hi there, The code is almost finished, it seems I cannot track the number of correct answers, basically my var "corr

My var correctAnswer does not increase more than +1, I'm lost how to fix this.

The rest of the code works fine.

//explaining the game rules, any question has either yes or no answer

alert("All questions have either yes or no pass/fail rules. Good luck");

var question1 = prompt("Is the earth center of universe?" + "You have guessed correctly" + correctAnswer + "answers"); var question2 = prompt("does water cover 70% of earth?"); var question3 = prompt("Can human grow to 100 years old?"); var question4 = prompt("Do dogs walk on 4 legs?"); var question5 = prompt("is internet awesome?"); var correctAnswer = 0; //tracking correct answers

//Each question has a yes/no condition, if it's a "yes" track them and post next to. Except how the fuck to do that??? //checking all questions if (question1 == "yes") { correctAnswer=+1; }

if(question2 == "yes") { correctAnswer=+1;}

if(question3 =="yes") { correctAnswer=+1;}

if(question4 == "yes") { correctAnswer=+1;}

if(question5 == "yes") { correctAnswer=+1;}

// code to calculate which crown the player has won. It has 4 possibilities var crown = "CrownColor"; if( correctAnswer === 5){ crown = "Gold crown"; } else if( correctAnswer === 4 || correctAnswer === 3) { crown = "Silver Crown"; } else if(correctAnswer === 2 || correctAnswer === 1) { crown = "Bronze Crown"; } else{ crown = "no crown at all"; }

//final message with total amount of correct answers and which crown the player is awarded. alert("Congratulations, you answered correctly " + correctAnswer + " and you have been awared to" + crown);

2 Answers

try using += where you currently have =+, the order is important. When you put = first, then the code assigns a positive number to the variable, rather than adding the number to the existing value.

Karen it worked !!! I was frustrating over such small mistake... hrr

THank you !