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 Review Conditional Statements and Comparison Operators

When a browser runs the code listed below, what will the user see?

please var spaceship =0; if (spaceShip===0) { alert("You are correct") } else {alert("you are wrong")}

please let me know the answer thanks!

2 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Amy, you got this. See code with comments below :)

// Declare a variable named spaceShips and set its value to be 0
var spaceShips = 0;

// Conditional check to see if the spaceShips variable has its value set to 0
if (spaceShips === 0 ) {
   // If spaceShips is 0, this code branch will be executed *hint*
   alert('You lose!');
} else {
  // If spaceShips is not 0, this code branch will be executed
  alert('You are still alive!');
}
Steve Warburton
Steve Warburton
4,156 Points

The answer is 'You Lose'...