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) Storing and Tracking Information with Variables Introducing Variables

For some reason the code in my workspace is'nt working. When I save my file and try to preview the code I get no alert

This is the code i'm writing in my workspace. But I just get a blank page. Keep in mind I have a macbook. Should I change some type of setting? Thanks!

var message = "Hello!"; alert("message");

Adrian Navarro
Adrian Navarro
7,424 Points

Other than my answer please let us know if you are using an external js file or an script tag directly in the html document. If nothing is happening then your code is not being executed.

try this in your HTML file above your ending body tag:

<script>
var message = "Hello!";
 alert(message);
</script>

If you are using an external js file then make sure you are calling the file in your html. Inside your <head> tag add something like:

<script src="yourfilename.js"></script>

5 Answers

Gary Haag
PLUS
Gary Haag
Courses Plus Student 1,314 Points

take the quotes off the alert message and it should work fine

Adrian Navarro
Adrian Navarro
7,424 Points
var message = "Hello!";
alert(message);

Remove the quotes from the variable: message. That should solve the issue; right now you should be getting an alert saying "message"

I did this but I still get no message at all.

Can you press command-shift-i after you run the project? Once you do that, do you see any text in red?

confirm if your browser have an option to enable or disable javascript

Erin Agobert
Erin Agobert
4,781 Points

This is going to seem really weird, but I was having the same problem with the exact same code after removing the quotes. This was my solution:

Old Script: var message = "Hello!"; alert(Message);

Note the capital "M" in the word "Message". Once I changed to "m" the script was able to execute.

New Script: var message = "Hello!"; alert(message);