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

Luke Gibson
Luke Gibson
4,822 Points

I have gotten this far but my score is not adding up at the end

When I complete the quiz my score is not adding up it just says that my score is 1 when it should be five.

// Quiz Questions to be asked var questionOne = prompt("True or False, Luke is learning to become a Web Developer?"); var questionTwo = prompt("True or False, Luke and Vicki are getting married in 2016?"); var questionThree = prompt("True or False, Luke and Vicki have a DOG called Dash?"); var questionFour = prompt("True or False, Vicki has a her 21st birthday this yeah?"); var questionFive = prompt("True or False, Luke has 3 brothers and Vicki has 1?"); var score = 0;

//Checking quiz questions answers
if (questionOne.toUpperCase() === 'TRUE') { score += 1; } else if (questionTwo.toUpperCase() === 'TRUE') { score += 1; } else if (questionThree.toUpperCase() === 'FALSE'){ score += 1; } else if (questionFour.toUpperCase() === 'TRUE') { score += 1; } else if (questionFive.toUpperCase() === 'TRUE') { score += 1; }

// end of quiz questions and answer checking document.write("Thank you for completeing the quiz, your score is " + score + " I hope you enjoyed it and come back to try again soon.")

1 Answer

Mustafa BaลŸaran
Mustafa BaลŸaran
28,046 Points

Hi Luke,

In your conditional statements what you would like to do here is to create a chain evaluation. If a question is answered correctly, that should add on the score and it should do so until the quiz is over. However, there is a big difference between 'if' and 'else if' statements and that is in case the first 'if' conditional is met, the following 'else if' conditionals will not be executed at all even if they are all evaluated to be true. On the other hand, you can check as many 'if' conditionals as you would like one after the other as they are not meant to check for situations that are mutually exclusive.

In short, please turn all 'else if' to 'if'. Your code should work. In fact, I tried it on the workspace.. and it is OK. One other small thing... you are misssing a ';' at the end of the script... That is document.write();

I hope that this is useful for you.

Mustafa is correct, you need to change the 'else if' statements to 'if' as when one of the else if statements or the original if states returns executes the rest will be skipped.