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

Tristyn Leos
Tristyn Leos
3,161 Points

Code doesn't run the final ELSE statement

I don't get it. The final ELSE statement at the bottom end, if you get 0 questions correct, doesn't show up. If you get 0 correct, it runs the last else IF statement. it says "Congradulations! You got 0 out of 5 correct. You get the BRONZE STAR!"

But that code should only run if you get 1 || 2 right. If you get 0, why does the final code not run?

I've tried changing the last ELSE statement to (else if score = 0 ), and i've even tried just "if score = 0) and it will NOT print the last line for some reason. Here is the code I'm using:

var score = 0 alert("Are you ready for the 5 question quiz?"); questionOne = prompt("What is 1+1"); if (parseInt(questionOne) === 2){ score = +1; } questionTwo = prompt("What is 1+1"); if (parseInt(questionTwo) === 2){ score = score + 1; } questionThree = prompt("What is 1+1"); if (parseInt(questionThree) === 2){ score = score + 1; } questionFour = prompt("What is 1+1"); if (parseInt(questionTwo) === 2){ score = score + 1; } questionFive = prompt("What is 1+1"); if (parseInt(questionFive) === 2){ score = score + 1; } alert("COMPLETE! Press OK to view your score"); if (score === 5){ document.write("Congradulations! You got " + score + " out of 5 questoins right!" + " You are awarded with the GOLD STAR!"); } else if (score === 3 || score === 4){ document.write("Congradulations! You got " + score + " out of 5 questoins right!" + " You are awarded with the SILVER STAR!"); } else if (score === 1 || 2){ document.write("Congradulations! You got " + score + " out of 5 questoins right!" + " You are awarded with the BRONZE STAR!"); //BELOW IS THE CODE THAT REFUSES TO RUN } else { document.write("Sorry. You got " + score + " out of 5 questions right." + " You get NO STAR!"); }

2 Answers

Chantal Jenkins
PLUS
Chantal Jenkins
Courses Plus Student 11,233 Points

Hi, In the following else if... you didn't complete the right hand side of the or properly.

You typed... else if (score === 1 || 2)

You should have

else if (score === 1 || score === 2)

Chantal is correct and just to add to understand why it evaluates to this condition look into truthy/falsy if you aren't familiar with them.

Tristyn Leos
Tristyn Leos
3,161 Points

OH. Thank you guys. Y'all are geniuses. And you're right - it worked