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

Michael LaCroix
Michael LaCroix
5,828 Points

Different approaches to same answer, not getting same answer

I tried two different methods of getting the answer and, in theory, they both should work, but the second one isn't.

First code block works document.write(playerScore); if( playerScore === 5){ document.write('Gold crown'); } else if (playerScore >= 2 ) { document.write('Silver crown'); } else if (playerScore === 1) { document.write('Bronze crown'); } else { document.write('No crown'); }

Second one doesn't. Something is wrong with the (2 || 3 || 4) but I can't figure out what.

document.write(playerScore); if( playerScore === 5){ document.write('Gold crown'); } else if (playerScore === 2 || 3 || 4) { document.write('Silver crown'); } else if (playerScore === 1) { document.write('Bronze crown'); } else { document.write('No crown'); }

2 Answers

Ryan Zimmerman
Ryan Zimmerman
3,854 Points

In JS you can't combine the 2||3||4 you have to compare each one individually. score === 2 || score === 3 || score === 4