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

Why isn't this code working?

My code is right so why do I keep getting told I didn't all the document.write fucntion?

index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>

<body>
</body>

alert("Hello from treehouse");
  document.write("<h1>Welcome to Javascript basics</h1>");

</script>

</html>
Simon Coates
Simon Coates
28,694 Points

A lot of these challenges have a preview button. Outputting javascript to the page as text usually means that something is up with your opening script tag. Otherwise for debugging, you use the challenge to create a real page, or sometimes run snippets of javascript in your browser's developer tools console to verify correctness.

3 Answers

Seth Kroger
Seth Kroger
56,413 Points

First, you need an opening <script> tag. The initial code provides it so it looks like you removed it by mistake. Second, there's a specific message it tells you to write, and you don't need the alert.

Simon Coates
Simon Coates
28,694 Points

it's particular. It wants document.write("Welcome to my site");

(update: As Seth Kroger notes, you seem to have accidentally removed your opening script tag. )

Thank you! I tried it every way I knew of and just forgot the script, second set of eyes is always helpful.