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 Introducing JavaScript Finishing the Game Control the Flow with Conditional Statements

Tsipporah Christopher
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tsipporah Christopher
Full Stack JavaScript Techdegree Graduate 15,593 Points

What's the difference between using an 'if' and an 'else if' statement when setting the conditions for the poison?

For example, when I simply use the 'if' statement for the poison it still works and lose points.

if (item.key === 'coin') {
      currentScore =  currentScore + 10;
if (item.key === 'poison') {
      currentScore =  currentScore - 25 ;
  }  

compared to

 if (item.key === 'coin') {
      currentScore =  currentScore + 10;
  } else  if (item.key === 'poison') {
      currentScore =  currentScore - 25 ;
  } 

Thanks!

2 Answers

As far as I can see there is no difference besides just clean code. Normally when you want to check multiple conditions you would use an if/else-if condition check. If only checking one condition you would be safe using just the if statement by itself. Anyone else feel free to give their two cents and correct me if I am wrong. I am still learning.