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) 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,646 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!