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 (Retired) Introducing JavaScript Your First JavaScript Program

David MacDonald
David MacDonald
919 Points

in script.js nothing is appearing when i use preview. How can i get the alert and header to appear?

I have the index.html file. Preview opens to port80 instead of web. Nothing appears after i enter the statement and command.

3 Answers

Jeff Wilton
Jeff Wilton
16,633 Points

There are three things to note, so lets take a look one at a time.

First, your index.html file should load the scripts.js file:


<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>JavaScript Basics</title>
  <div class="container">
  <script src="scripts.js"></script>

Second, your scripts.js file should have an alert statement and a document.write statement:


alert("Hello from Treehouse!");
document.write("<h1>Welcome to Javascript Basics</h1>");

Third, when you open the preview window, it should go to port 80 with a URL something like this: http://port-80-i0up09r7h4.treehouse-app.com/

(this URL is unique to me, so use whatever URL opens when you click preview in your workspaces.

If you do all of the above and you still don't see the alert in the preview window, then try doing a hard refresh (Ctrl+Shift+R in Firefox or Chrome) or clear your browser cache.

Hope this helps!

Tre Dudman
Tre Dudman
10,575 Points

Ctrl+Shift+R did the trick, thanks heaps!