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 trialMartin Lindsey
11,273 PointsThe preview doesn't work on my browser until I refresh the tab and then only the first alert displays.
The text never appears and neither does the second alert message.
Anyone else having this problem?
I'm working on a Mac using the Firefox browser.
8 Answers
Daniel Gauthier
15,000 PointsHey Martin,
I just ran through this exercise following along with Dave's instructions. Try checking your code against this:
alert("Hello from Treehouse");
document.write("<h1>Welcome to JavaScript Basics</h1>");
alert("Thanks for visiting.");
Make sure you're not missing a semi-colon or a closing set of quotations. If it all looks good, try posting your code so we can look under the hood for you.
Also, if you're wondering how to post your code into the forums, follow this:
How to Post Code on the Forums
There are two ways to share your code on the forums here, excluding using external tools from outside of Treehouse.
Method One
The first method is to use a series of three ` (backticks, located at the top left of the keyboard) without any spaces on one line, paste all of your code starting on the second line, then closing the code block with a second series of three backticks. Take a peek at the link for the "Markdown Cheatsheet" located above the "Post Answer" button anytime you're about to post a comment or answer. Using this method, the code will look like this, if you replace the apostrophes with backticks:
'''css
(code here)
'''
Method 2
The second method is a little more convoluted, but it lets us look at your entire project and make our own copy to try fixing issues. I'll order the steps since it can be a little confusing the first time around:
Open the workspace you're having trouble with.
On the menu bar located to the left of the "Preview Workspace" button is the "Snapshot Workspace" (camera icon), click that.
A popout will appear with another button that says "Take Snapshot", click that.
It should create a new snapshot, which will appear beneath the "Take Snapshot" button in the popout. Click the snapshot you want to share.
The snapshot should open a new browser tab. Highlight the url in the snapshot's browser tab (it should look like this: https://w.trhou.se/ducj79b1i0 ).
Create your forum post and paste the snapshot's url into the post. Other Treehouse users will be able to open the snapshot, then 'fork' a new copy to check out.
Keep in mind that you can only ever have five snapshots, but you can delete them by hovering over the snapshot located below the "Take Snapshot" button in the popout and click the trash bin icon.
Good luck!
Jennifer Nordell
Treehouse TeacherNot being able to see your code, it's hard to say exactly. But I'd check the browser settings just to make sure you're not somehow inadvertently blocking pop-ups. Keep in mind that the alert counts as just that.
Daniel Gauthier
15,000 PointsHey Mathew,
Switch the apostrophes with backticks, I use apostrophes in the example above because it will trigger the code block otherwise.
As for the actual problem, I understand now. If you view a javascript file that isn't linked to anything in Chrome, it will just output the lines within the file as typed. Try linking the script to a barebones index.html file and it will work as intended.
Good luck!
Matthew Ashman
4,364 PointsI'm having similar challenges as the initial poster. I'm using textwrangler as my editor - and have saved the file as playaround.js (if that matters). Using a chrome browser, and the text shows up - exactly how it is presented to the browser:
'''js alert("Hello from Treehouse"); document.write("<h1>Welcome to JavaScript Basics</h1>"); alert("Thanks for visiting.");'''
Daniel Gauthier
15,000 PointsHey Mathew,
Is the first line of playaround.js:
js alert("Hello from Treehouse");
?
Matthew Ashman
4,364 PointsNo, sorry that my post was not formatted clearly; I attempted to show that it was javascript. It is written as shown:
''' alert("Hello from Treehouse"); document.write("Welcome to JavaScript Basics"); alert("Thanks for visiting."); '''
right now, I'm viewing this document as a single js document, not linked to anything at all. Could this be a reason why the interactivity is not working when viewed through chrome? Or should it work regardless of being a single js document?
And when I mean "a single js document", I mean that it is not linked to an index.html file like the example shown in Daves tutorial. Any help is appreciated - I am a budding developer with a long ways to go!
Martin Lindsey
11,273 PointsI'll use those tips going forward with any issues.
The rest of the coding examples have been going fine.
It may just be my getting used to this platform.
Thanks for the help.
griffingoodman
4,137 PointsI had same issue. It most likely isn't your code. You have to refresh the browser because the page is cached. So refreshing your browser refreshes the cache.
Eliot Clarke
4,664 PointsI hate to tell on myself for something so silly, but I figured out that my alerts were not showing up at first because I didn't save my file before hitting preview. A quick command + s, and my alert showed up immediately. Excuse: This is my first time using the workspace. Like I said, I feel pretty ridiculous, but that might help someone.
Daniel Gauthier
15,000 PointsDaniel Gauthier
15,000 PointsI just did my best to break the exercise and found the program will run the first alert, then not display the h1 element or the second pop-up if there's a typo in the document.write part of the document.write statement.
Hope this helps, good luck with the course!