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 trialKevin Leong
1,664 PointsNo 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
Treehouse Guest TeacherHi 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.
Kyle Salisbury
Full Stack JavaScript Techdegree Student 16,363 PointsSee Robert's answer. Also I would add, make sure you are hitting "save" before preview.
Steven Chamberlain
506 PointsYup, it was not hitting 'save' that was causing the issue for me. Thanks for the reminder (even if it was almost 2 years ago :D)