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

Jonathan Hull
Jonathan Hull
5,606 Points

Hi, is there a way to terminate the program based on an initial question.

var start = prompt("Hello! Are you ready to play a game?");
var correct = 0;
var yes = false;

if (start.toLowerCase() === "yes") {
yes = true;
} else {
    yes= false;
}

if (yes = false) { 
    document.write("We are done here");
} 

then the rest of the code.

I can get the program to spit out the we are done here part, but the rest of the program still runs.

Thanks

1 Answer

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

Hey Jonathan, your else statement is not needed because the variable yes is set to false to start with. Try this:

var start = prompt("Hello! Are you ready to play a game?");
var correct = 0;
var yes = false;

if (start.toLowerCase() === "yes") {
  yes = true;
} 

if (yes == false) { 
    document.write("We are done here");
}