Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Introducing Conditional Statements

No code is running

For the assignment Introducing Conditionals I opened the workspace and typed this into the workspace:

const answer = prompt('Which planet is closest to the sun?');

if ( answer === 'Mercury' ) { alert(${answer} is the correct answer!); } else { alert(Sorry ${answer} is not the correct answer!); }

For some reason when I run the code nothing seems to happen and I don't see any errors in the inspector. I also tried doing the exact same thing as Guil did to no avail:

const answer = prompt('Which planet is closest to the sun?');

if ( answer === 'Mercury' ) { console.log("That's correct!"); } else { console.log("Sorry, that's incorrect"); }

Didn't touch the HTML at all which is: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript Basics</title> <link href="css/style.css" rel="stylesheet"> </head> <body> <main></main> <script src="js/conditionals.js"></script>
</body> </html>

2 Answers

Robert Manolis
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Robert Manolis
Treehouse Guest Teacher

Hi Kevin,

First, double check script tag near the bottom the index.html file and make sure that the JS file you're working in is actually connected to the HTML.

Then once you're sure you're working in the correct file, click the preview button in the top right corner of your Workspace, and once the page opens in the browser, open the Chrome DevTools console. If everything is hooked up, you should see some errors if you're using the first block of code you shared. The reason is that you're missing the backticks around your strings. When creating strings where you're trying to use interpolation like this, ${answer} is the correct answer!, you need to wrap that string in backticks.

Hope that helps. :smiley: